好的,我有一些我正在构建的网站的代码。我有一个数据绑定到 SqlDataSource 的列表框。选中后,它应该生成一个 SQL 查询,该查询更新\过滤页面中的其他列表框。我试过测试它只是为了让它改变标签的文本,这甚至不起作用。这是我的一些代码:
<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>
现在在我的 C# Codebehind 我有这个:
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;
}
但仍然没有更新测试仪。即使 AutoPostBack=true,即使整个事情都包含在更新面板中。=(我需要一些帮助来解决这个问题。我也将不胜感激任何其他建议。我很乐意提供您可能需要的任何其他信息,请在评论中告诉我。