Wednesday, August 18, 2010

How to select that cells?

I'm using asp.net (C#), i have a grid view like below:





ID


01 Edit


02 Edit


03 Edit





Then have code:





protected void ibtnEdit_Click(object sender, ImageClickEventArgs e)


{


foreach (GridViewRow gvr in gvwThreads.Rows)


{


Literal litId = (Literal)gvr.FindControl(';litId';);


Response.Redirect(';A.aspx?ID='; + litId.Text, true);


}


}





The edit in the gridview is imagebutton that will link to page A.aspx. When i click on id 01 edit, it'll go to A.aspx with 01 details. But when i click on id 02 or 03 edit, it also go to A.aspx with 01 details but not 02 or 03 details.





Why this happened? How to fix it when i click 01 edit it'll go A.aspx with 01 details %26amp; click 02 or 03 edit will go A.aspx with 02 or 03 details?How to select that cells?
I don't write in C# so you'll have to translate the syntax but...





I think your ForEach loop is assigning ALL rows to the litID. But it quits when it fills the first time. So you need to make sure you're assigning the selected row.





Try a conditional to check the row index = the selected index, like:


For each ...Rows


FindControl


If litID = e (your event argument)


Response.Redirect(';A.aspx?ID='; + litId.Text, true);


end if


NextHow to select that cells?
try





string str





str = GridViewRow.CurrentRow.Cells[0].Value.To鈥?br>




Response.Redirect(';A.aspx?ID='; + str,True);

No comments:

Post a Comment