Datgrid - Selected Index

fullyii

Member
Joined
Aug 19, 2005
Messages
22
Location
Chicago
Programming Experience
1-3
I am trying to use a function that will display the correct item in a dropdown list. This dropdown list will be used to update a database. Everything is working except the function that selects the appropriate listbox item. Once I add the selectedIndex... I get the following error.

System.IndexOutOfRangeException: faqCategoryID

Any help would be greatly appreciated!

********** HTML********************

<asp:DropDownList Runat="server" ID="lstCategories" DataValueField="faqCategoryID" DataTextField="faqCategoryName" DataSource="<%# GetCategories() %>" SelectedIndex='<%# GetSelIndex(Container.DataItem("faqCategoryID")) %>' />
************FUNCTION********************
Function GetSelIndex(ByVal CID As String) As Integer
Dim iLoop As Integer
Dim dt As DataTable = ddlDataSet.Tables("Categories")
For iLoop = 0 To dt.Rows.Count - 1
If Int32.Parse(CID) = Int32.Parse(dt.Rows(iLoop)("faqCategoryID")) Then
Return iLoop
End If
Next iLoop
End Function
 
Back
Top