|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
ASP.net 2.0 DropdownList bound to SQLDataSource and setting SelectedIndexhave a couple of questions: 1) Because they are bound to the same datasource, I am assuming that they only make 1 round trip to the DB server -- is that correct? 2) On a user's click of a button, one of the actions in the button OnClick event is to set the selectedindex of the 2nd DDL to that of the 1st. I get a runtime error here that says that the given index is not in the list of items. Is this because the button event is firing before the listitems are populated? If so how do I get the list items to populate 1st? Also the list items will probably not change in the term of a user session, is there a way to prevent the page from retreiving the listitems on each postback? Here is my relevant code: <asp:SqlDataSource ID="dsICD9" runat="server" ConnectionString="<%$...%>" SelectCommand="..."> </asp:SqlDataSource> <asp:DropDownList AppendDataBoundItems="true" ID="ddl1" runat="server" DataSourceID="dsICD9" onkeypress="return KeySortDropDownList_onkeypress(this,false)" DataTextField="description" DataValueField="ICD9"> <asp:ListItem Selected="True"></asp:ListItem> </asp:DropDownList> <asp:DropDownList AppendDataBoundItems="true" ID="ddl2" runat="server" DataSourceID="dsICD9" onkeypress="return KeySortDropDownList_onkeypress(this,false)" DataTextField="description" DataValueField="ICD9"> <asp:ListItem Selected="True"></asp:ListItem> </asp:DropDownList> Protected Sub AddCPT_Click(ByVal sender As Object, ByVal e As System.EventArgs) ... ddl2.SelectedIndex = ddl1.SelectedIndex <-----Here's where I get the runtime error ... End Sub > 1) Because they are bound to the same datasource, I am assuming that Yes.> they only make 1 round trip to the DB server -- is that correct? > in the list of items. Is this because the button event is firing Bind the data to the 2nd DDL before setting the SelectedIndex.> before the listitems are populated? If so how do I get the list items > to populate 1st? Also the list items will probably not change in the -- Happy Hacking, Gaurav Vaish | http://www.mastergaurav.com http://www.edujinionline.com http://articles.edujinionline.com/webservices -------------------
Other interesting topics
Space in fileupload control
How do I return the name (ID) of a user control? add a link button to prev/next in a wizard asp:TextBox Binding an array to a DropDownList How to implement interface's method in aspx? Default Border Color for Dropdownlist Control? calendar control - weekends word wrap in ultrawebtree word wrap in ultrawebtree |
|||||||||||||||||||||||