Hi,
I have an editable DataGrid which lists product information. When a row is
in editing mode, there is a DropDownList for changing the product category.
The code is like this:
<EditItemTemplate>
<asp

ropDownList Runat="server" ID="EditCategory"
DataValueField="categoryID" DataTextField="categoryName"
DataSource="<%# GetCategories() %>"
SelectedIndex='<%# GetCategoryIndex(Container.DataItem["categoryID"]) %>' />
</EditItemTemplate>
The method GetCategories() returns a DataSet with categoryID & categoryName.
The method GetCategoryIndex is supposed to return the index of the original
selection Container.DataItem["categoryID"] like this:
protected int GetCategoryIndex (int categoryID)
{
int indexValue = 0;
int i;
DataSet dsCategories = GetCategories();
for (i=0; i<dsCategories.Tables[0].Rows.Count; i++)
{
if (Int32.Parse(dsCategories.Tables[0].Rows[i]["categoryID"].ToString())
== categoryID)
{
indexValue = i;
}
}
return indexValue;
}
The code is compiled without a problem, but when the page loads, it gives an
error message:
CS0021: Cannot apply indexing with [] to an expression of type 'object'
What does it mean?
I thought something was wrong with my GetCategoryIndex () so I changed it to:
protected int GetCategoryIndex (int categoryID)
{
return 3;
}
But it still gives the same error. What's wrong?
Thanks.
WB.