Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > ASP.net 2.0 DropdownList bound to SQLDataSource and setting SelectedIndex

Reply
Thread Tools

ASP.net 2.0 DropdownList bound to SQLDataSource and setting SelectedIndex

 
 
Jason Wilson
Guest
Posts: n/a
 
      09-13-2006
I have two dropdownlists that are bound to the same datasource and I
have 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>

<aspropDownList AppendDataBoundItems="true" ID="ddl1"
runat="server" DataSourceID="dsICD9"
onkeypress="return KeySortDropDownList_onkeypress(this,false)"
DataTextField="description" DataValueField="ICD9">

<asp:ListItem Selected="True"></asp:ListItem>
</aspropDownList>

<aspropDownList AppendDataBoundItems="true" ID="ddl2"
runat="server" DataSourceID="dsICD9"
onkeypress="return KeySortDropDownList_onkeypress(this,false)"
DataTextField="description" DataValueField="ICD9">

<asp:ListItem Selected="True"></asp:ListItem>
</aspropDownList>

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
When I set the DropDownList.SelectedIndex of ONE DropDownList they ALL change! S_K ASP .Net 5 11-14-2007 04:51 PM
DropDownList inside GridView: How to set SelectedIndex for the DropDownList? keithb ASP .Net 1 11-01-2006 05:24 AM
ASP.net 2.0 DropdownList bound to SQLDataSource and setting SelectedIndex Jason Wilson ASP .Net 1 09-14-2006 02:36 PM
Setting the SelectedIndex of a DropDownList in a Datagrid K Bryan ASP .Net 4 04-15-2004 09:08 PM
Finding an index in a dataset and setting SelectedIndex on dropdownlist wrecker ASP .Net Web Controls 1 02-13-2004 10:07 PM



Advertisments