我正在尝试创建两个下拉列表,第一个带有用户列表,第二个只有当我单击“确定”按钮时才可见,显示用户的帐户列表。aspx 页面代码如下:
User:
<asp:SqlDataSource id="sourceUsers" runat="server" ConnectionString="<%$ ConnectionStrings:ct2012 %>"
SelectCommand="SELECT name, id FROM users" />
<asp:DropDownList id="codUsers" runat="server" DataSourceID="sourceUsers"
DataTextField="name" DataValueField="id" AutoPostBack="true" >
</asp:DropDownList>
<br />
Conto:
<asp:SqlDataSource id="sourceAccounts" runat="server" ConnectionString="<%$ ConnectionStrings:ct2012 %>" />
<asp:DropDownList id="accUsers" runat="server" DataSourceID="sourceAccounts"
DataTextField="code" DataValueField="id" Visible="false" >
</asp:DropDownList>
<br />
<asp:Button ID="btOK" text="OK" OnClick="cmdNew_Click" runat="server" />
处理按钮事件的c#代码是:
protected void cmdNew_Click(object sender, EventArgs e)
{
sourceAccounts.SelectCommand = "SELECT code, id FROM accounts WHERE ID_user=" + codUsers.DataValueField;
accUsers.Visible = true;
}
问题是 codUsers.DataValueField 返回字符串“id”而不是索引的值....