attempt to find cell id using control

W

WebBuilder451

I'm attempting find the cell id, i (e.row.cells ) given a control in that
cell.
using this function:
private int GetcellPosition(GridViewRow gvr, string ctrlID)
{
var iCell = -1;
for (int i = 0; i < gvr.Cells.Count; i++ )
{
if ( gvr.Cells.FindControl(ctrlID) != null )
{
iCell = i;
break;
}
}
return iCell;
}
CALL: e.Row.Cells[GetcellPosition(e.Row, "LabelPerBS")].CssClass= "gvir2";

this does not work. It appears to be doing a find on the entire row so the
first position always gets returned. Is there a way to do this or am i
hitting a limitation?

thanks

kes
 
B

bruce barker

all the cell have the same NamingContainer (which is what FindControl uses).
you will have to search each cells Control collection (maybe recursivly) for
a control with the desired ID.

-- bruce (sqlwork.com)
 
W

WebBuilder451

bruce, i appreciate your response,

I think that is what i was trying to do, but i don't know how to isolate
each cell so that i can get to the collection.
i tried var Tablecell td = e.row.cells;
and for reasons you noted it does not work. I don't think a recursive call
will change this(?)


--
(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


bruce barker said:
all the cell have the same NamingContainer (which is what FindControl uses).
you will have to search each cells Control collection (maybe recursivly) for
a control with the desired ID.

-- bruce (sqlwork.com)


WebBuilder451 said:
I'm attempting find the cell id, i (e.row.cells ) given a control in that
cell.
using this function:
private int GetcellPosition(GridViewRow gvr, string ctrlID)
{
var iCell = -1;
for (int i = 0; i < gvr.Cells.Count; i++ )
{
if ( gvr.Cells.FindControl(ctrlID) != null )
{
iCell = i;
break;
}
}
return iCell;
}
CALL: e.Row.Cells[GetcellPosition(e.Row, "LabelPerBS")].CssClass= "gvir2";

this does not work. It appears to be doing a find on the entire row so the
first position always gets returned. Is there a way to do this or am i
hitting a limitation?

thanks

kes
 
B

bruce barker

assuming your control is not nested (which would require recursion):

for (int i = 0; i < gvr.Cells.Count; i++ )
{
foreach (Control c in gvr.Cells.Controls)
{
if (c.ID == ctrlID)
return i;
}
}


-- bruce (sqlwork.com)


WebBuilder451 said:
bruce, i appreciate your response,

I think that is what i was trying to do, but i don't know how to isolate
each cell so that i can get to the collection.
i tried var Tablecell td = e.row.cells;
and for reasons you noted it does not work. I don't think a recursive call
will change this(?)


--
(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


bruce barker said:
all the cell have the same NamingContainer (which is what FindControl uses).
you will have to search each cells Control collection (maybe recursivly) for
a control with the desired ID.

-- bruce (sqlwork.com)


WebBuilder451 said:
I'm attempting find the cell id, i (e.row.cells ) given a control in that
cell.
using this function:
private int GetcellPosition(GridViewRow gvr, string ctrlID)
{
var iCell = -1;
for (int i = 0; i < gvr.Cells.Count; i++ )
{
if ( gvr.Cells.FindControl(ctrlID) != null )
{
iCell = i;
break;
}
}
return iCell;
}
CALL: e.Row.Cells[GetcellPosition(e.Row, "LabelPerBS")].CssClass= "gvir2";

this does not work. It appears to be doing a find on the entire row so the
first position always gets returned. Is there a way to do this or am i
hitting a limitation?

thanks

kes
 
Y

Yankee Imperialist Dog!

Thank you, i understand why mine did not work. Youer help was greatly
appreciated.

Thanks
KES

bruce barker said:
assuming your control is not nested (which would require recursion):

for (int i = 0; i < gvr.Cells.Count; i++ )
{
foreach (Control c in gvr.Cells.Controls)
{
if (c.ID == ctrlID)
return i;
}
}


-- bruce (sqlwork.com)


WebBuilder451 said:
bruce, i appreciate your response,

I think that is what i was trying to do, but i don't know how to isolate
each cell so that i can get to the collection.
i tried var Tablecell td = e.row.cells;
and for reasons you noted it does not work. I don't think a recursive call
will change this(?)


--
(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


bruce barker said:
all the cell have the same NamingContainer (which is what FindControl uses).
you will have to search each cells Control collection (maybe recursivly) for
a control with the desired ID.

-- bruce (sqlwork.com)


:

I'm attempting find the cell id, i (e.row.cells ) given a control in that
cell.
using this function:
private int GetcellPosition(GridViewRow gvr, string ctrlID)
{
var iCell = -1;
for (int i = 0; i < gvr.Cells.Count; i++ )
{
if ( gvr.Cells.FindControl(ctrlID) != null )
{
iCell = i;
break;
}
}
return iCell;
}
CALL: e.Row.Cells[GetcellPosition(e.Row, "LabelPerBS")].CssClass= "gvir2";

this does not work. It appears to be doing a find on the entire row so the
first position always gets returned. Is there a way to do this or am i
hitting a limitation?

thanks

kes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top