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********************
************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
System.IndexOutOfRangeException: faqCategoryID
Any help would be greatly appreciated!
********** HTML********************
<aspropDownList Runat="server" ID="lstCategories" DataValueField="faqCategoryID" DataTextField="faqCategoryName" DataSource="<%# GetCategories() %>" SelectedIndex='<%# GetSelIndex(Container.DataItem("faqCategoryID")) %>' />
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