Problem Binding DS to DropDownList

W

Wayne Wengert

I am trying to use the built-in SQLConnection, SQLDataAdapter and Dataset
components to populate the items in a DropDown List. I configured the
connection, adapter anbd dataset and can preview the data. In the PageLoad
event I have the following code:
-------------------------------
SqlDataAdapter1.Fill(DataSet11, "Regional")

DropDownList1.DataBind()

-------------------------------

When I run the page I get the following error. I am not certain what it is
saying? Any pointers will be appreciated.

===========================================
Index 0 is not non-negative and below total rows count.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: Index 0 is not
non-negative and below total rows count.

Source Error:

Line 22: <asp:ListItem Value="Perc">Perc</asp:ListItem>
Line 23: </asp:RadioButtonList>
Line 24: <asp:DropDownList id=DropDownList1 style="Z-INDEX: 105; LEFT:
216px; POSITION: absolute; TOP: 104px" runat="server" Width="169px"
Height="24px" DataSource='<%# DataBinder.Eval(DataSet11,
"Tables[Regionals].DefaultView.[0].RegionalID") %>'
DataTextField="RegionalID" DataMember="Regionals"
DataValueField="RegionalID" AutoPostBack="True">
Line 25: </asp:DropDownList>
Line 26: <asp:Label id="Label4" style="Z-INDEX: 106; LEFT: 219px;
POSITION: absolute; TOP: 82px" runat="server"
 
S

Saravana

You are accessing the datatable with wrong name.. change your datasource
property of dropdownlist like this, it will work..
DataSource='<%# DataBinder.Eval(DataSet11,
"Tables[Regional].DefaultView.[0].RegionalID") %>'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,816
Latest member
nipsseyhussle

Latest Threads

Top