protected void ExercisesGridView_SelectedIndexChanged(object
sender, EventArgs e)
{
GridViewRow row = ((GridView)sender).SelectedRow;
String Name = row.Cells[2].Text;
String Description = row.Cells[3].Text;
String ExerciseType = row.Cells[4].Text;
...
best regards
> As of now I execute the following code when selecting a row in a
> gridview. However can I somehow refer to the cells by name rather then
> their index? eg. String Name = row.Cells["Name"].Text;
Not natively. You could, I suppose, create a dictionary of the cells and
their relative number, but that seems like an unnecessary amount of work...
What problems are you having referring to the cells by their numerical
position in the row...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
I'm using this for business objects, loading them into lists with
datareaders. Much cleaner than TableAdapters and faster!
Given i can do this for the above:
Address ADR = new Address(); // object
ADR.BActive = DR.GetBoolean(DR.GetOrdinal("bActive"));
......
......
instade of DR for datareader it would be GVR for GridViewRow.
Maybe the holy grail for me and others would be a strongly typed gridview,
listview, ... However, That will do more than raise a few eyebrows, it would
also kill performance. I'm using Custom Business sobjects instead of
TableAdapters/DataSets for performance and control reasons now. Could a
custom gridView "Row" object be created?
Not meaning to add fuel to a fire, I'm serious i'd like something like that
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)
kes
kes
"Seb" wrote:
> ....
>
>
> best regards
>
I wont bother with that...
> What problems are you having referring to the cells by their numerical
> position in the row...?
>
As WebBuilder451 points out... changing of order, adding and dropping
and so on.
Thanks for the reply.
I was just surprised that I couldn't a native way... I wont bother
with that. Thanks anyways
> The biggest problem i have is the order changes, cells are dropped, added.
OK.
> I'd love it if there were a way to do this w/o having to create the
> dictionary.
AFAIK, there isn't, at least, not with the existing GridView webcontrol. Of
course, there's nothing to prevent you from creating an enhanced Grid
control which maybe uses the current one as its starting point...
> Maybe the holy grail for me and others would be a strongly typed gridview,
> listview, ...
From what you're saying, you don't really need a strongly-typed GridView per
se, since you're not interested in what *type* of data exists in each of the
cells (it's just text anyway by the time it's rendered to the client
browser), but rather a way to refer to a Cell in a Cells collection by a
name rather than by its zero-based numerical position within the Cells
collection...
Which leads me to think that the Dictionary route is probably the simplest
method...