Okay I have some code for a website I am building. I have a listbox that is databound to an SqlDataSource. When selected, it is supposed to generate an SQL query that updates\filters a different listbox elsswhere in the page. I have tried testing it just to get it to change the text of a Label and that isn't even working. Here is some of my code:
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<%--register triggers for Partial postback --%>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="showbutton" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="viewapps" EventName="Click" />
</Triggers>
<ContentTemplate>
<%--- the controls in their rows and columns --%>
<%--column 1 --%>
<asp:Label runat="server" ID="TESTER">Text</asp:Label>
<asp:Panel runat="server" CssClass="column1">
<asp:Panel ID="Panel1" runat="server" CssClass="row1">
<%-- Make Panel --%>
<span style="padding:8px; position:relative;">
<asp:Label ID="label1" runat="server" Text="Make" Font-Size="Large" ></asp:Label>
<asp:Listbox ID="MakeList" runat="server" Width="166px" SelectionMode ="Multiple" DataSourceID="MakeSource" DataTextField="MakeName" AutoPostBack="true" DataValueField="MakeID" OnSelectedIndexChanged="UpdateModels">
</asp:Listbox>
</span>
<asp:SqlDataSource ID="MakeSource" runat="server" ConnectionString="<%$ ConnectionStrings:VCDBConnectionString %>" ></asp:SqlDataSource>
</asp:Panel>
Now in my C# Codebehind I have this:
public void UpdateModels(object sender, EventArgs e)
{
//build a string for a SQL query for the Models
string newQuery = "SELECT M.[ModelID], M.[ModelName] FROM Model M INNER JOIN BaseVehicle BV ON BV.ModelID = M.ModelID Where BV.MakeID= '";
string test = "";
foreach (ListItem li in MakeList.Items)
{
//add each piece of the selected text to the string
if (li.Selected)
{
test += li.Value;
test += "' AND BV.MakeID= '";
}
int cleanup = test.LastIndexOf("' AND BV.MakeID= '");
test.Remove(cleanup-19,cleanup);
//ScriptManager.RegisterStartupScript(this, GetType(), "ServerControlScript", "alert('" + test + "');", true);
TESTER.Text = test;
}
But still tester is not being updated. Even though AutoPostBack=true, even though the whole thing is wrapped in an update panel. =( I need some help figuring this one out. I would also appreciate any other advice. I would be glad to provide any additional information you may need, just let me know in the comments.