Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > attempt to find cell id using control

Reply
Thread Tools

attempt to find cell id using control

 
 
WebBuilder451
Guest
Posts: n/a
 
      12-10-2008
I'm attempting find the cell id, i (e.row.cells[i] ) 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[i].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
 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      12-10-2008
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" wrote:

> I'm attempting find the cell id, i (e.row.cells[i] ) 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[i].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

 
Reply With Quote
 
 
 
 
WebBuilder451
Guest
Posts: n/a
 
      12-10-2008
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[i];
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" wrote:

> 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" wrote:
>
> > I'm attempting find the cell id, i (e.row.cells[i] ) 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[i].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

 
Reply With Quote
 
bruce barker
Guest
Posts: n/a
 
      12-11-2008
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[i].Controls)
{
if (c.ID == ctrlID)
return i;
}
}


-- bruce (sqlwork.com)


"WebBuilder451" wrote:

> 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[i];
> 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" wrote:
>
> > 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" wrote:
> >
> > > I'm attempting find the cell id, i (e.row.cells[i] ) 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[i].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

 
Reply With Quote
 
Yankee Imperialist Dog!
Guest
Posts: n/a
 
      12-11-2008
Thank you, i understand why mine did not work. Youer help was greatly
appreciated.

Thanks
KES

"bruce barker" wrote:

> 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[i].Controls)
> {
> if (c.ID == ctrlID)
> return i;
> }
> }
>
>
> -- bruce (sqlwork.com)
>
>
> "WebBuilder451" wrote:
>
> > 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[i];
> > 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" wrote:
> >
> > > 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" wrote:
> > >
> > > > I'm attempting find the cell id, i (e.row.cells[i] ) 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[i].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

 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Find which Cell is clicked by user in GridView control of Asp.net Mrinalini Pande ASP .Net Datagrid Control 0 11-23-2006 05:34 AM
Can't locate object method "first" via package "attempt" (perhaps you forgot to load "attempt"?) at .... GMI Perl Misc 3 06-19-2005 10:44 PM
How to set and highlight text in JTable cell on selection and/or invoke cell editor directly. news.rcn.com Java 1 07-12-2004 10:22 PM
RadioButtonList In A DataGrid Cell - Can I find the selected button without editing the cell? Empire City ASP .Net Datagrid Control 3 04-30-2004 12:19 AM
multilink cell phones multilinking shotgun 2 cell phones Calvin Cisco 1 11-07-2003 02:20 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57