Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI geeks,

Need some clarification. I am using a gridview with enough no of rows and columns.
At footer, I've a button to add new row in gridview. My gridview consists of input controls like radiobutton, textboxes, etc.

My doubt is : I've a radiobuttonlist in all rows in gridview and when I click the listitem in radiobuttonlist, I need to know that which row(ROWINDEX) the radiobuttonlist was selected for some requirement.

I used this code
C#
int rowIndex=gv.SelectedIndex;

I clicked the radiobutonlist at 5th row and rowIndex returns -1.

Can you help us?

Thanks
Posted

1 solution

try this

C#
protected void Gender_SelectedIndexChanged(object sender, EventArgs e)
{
RadioButtonList rdb= (RadioButtonList )sender;

GridViewRow grdRow = (GridViewRow)rdb.NamingContainer;
//OR
GridViewRow grdRow = ((GridViewRow)rdb.Parent.Parent);
//You can find control like this
 Label objLabel = (Label)grdRow.FindControl("ControlIDfromgridview");
//OR
//you can find cell value 
String str= grdRow.Cells[0].Text;
}
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900