accessing row in gridview
-
Hi I have an event for the onrow databound When I try and find one of the controls using
HyperLink hyp5 = ((HyperLink)e.Row.FindControl("hl"));
it shows an object reference error. However when I use:
for (int x = 0; x < GridView4.Rows.Count; x++)
{
GridViewRow row = GridView4.Rows[x];
HyperLink hyp = ((HyperLink)row.FindControl("hl"));it works. The problem is, it is slowing my app down by using the second method. How can I find the control using the first method? thnaks.
-
Hi I have an event for the onrow databound When I try and find one of the controls using
HyperLink hyp5 = ((HyperLink)e.Row.FindControl("hl"));
it shows an object reference error. However when I use:
for (int x = 0; x < GridView4.Rows.Count; x++)
{
GridViewRow row = GridView4.Rows[x];
HyperLink hyp = ((HyperLink)row.FindControl("hl"));it works. The problem is, it is slowing my app down by using the second method. How can I find the control using the first method? thnaks.
I believe that a GridView row can be accessed only by using GridViewRow. For eg: foreach (GridViewRow gvr in GridView1.Rows) { CheckBox cb = (CheckBox)gvr.FindControl("chkbox1"); if (cb.Checked) { string Username = gvr.Cells[1].Text; } }. This will work. But if you didn't use a GridViewRow object, you will not get the cell text of a particular row. Hope this helps.
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
-
I believe that a GridView row can be accessed only by using GridViewRow. For eg: foreach (GridViewRow gvr in GridView1.Rows) { CheckBox cb = (CheckBox)gvr.FindControl("chkbox1"); if (cb.Checked) { string Username = gvr.Cells[1].Text; } }. This will work. But if you didn't use a GridViewRow object, you will not get the cell text of a particular row. Hope this helps.
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
Thanks for replying, however I have another question now: If I have an event using onrowdatebound, how can I access the current datakey for the row? Ive tried for (int x = 0; x < GridView4.Rows.Count; x++) { string ref2 = GridView4.DataKeys[x].Values[1].ToString(); but is there a way to get it using e.row? The reason is I dont want to have to run a loop in my rowdatabound event. thanks