ASP.NET: DataValueField in DropDownList

Junk

New Member
I'm trying to create two dropdownlist, the first one with a list of users, and the second one visible only when i click the OK button, showing a list of accounts for the user. The aspx page has the following code:\[code\]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" />\[/code\]The c# code to handle the button event is:\[code\]protected void cmdNew_Click(object sender, EventArgs e) { sourceAccounts.SelectCommand = "SELECT code, id FROM accounts WHERE ID_user=" + codUsers.DataValueField; accUsers.Visible = true; }\[/code\]The problem is that codUsers.DataValueField returns me the string "id" instead of the value of the index....
 
Back
Top