PC Review


Reply
Thread Tools Rate Thread

SelectedIndex for DropDownList in DataGrid

 
 
=?Utf-8?B?V0I=?=
Guest
Posts: n/a
 
      22nd May 2005
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>
<aspropDownList 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
set Dropdownlist SelectedIndex in a DataGrid marcbb Microsoft C# .NET 1 29th May 2007 05:47 PM
set Dropdownlist SelectedIndex in a DataGrid marcbb Microsoft C# .NET 2 29th May 2007 12:22 PM
set dropdownlist selectedindex in datagrid pleaseexplaintome@yahoo.com Microsoft ASP .NET 1 26th Feb 2007 11:22 AM
SelectedIndex of Dropdownlist in Datagrid Kay Chan Microsoft ASP .NET 2 6th Jan 2005 11:47 AM
Setting the SelectedIndex of a DropDownList in a Datagrid K Bryan Microsoft ASP .NET 4 15th Apr 2004 11:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:43 PM.