如何获取具有webcontrols的gridiview的当前rowindex [英] How to get the current rowindex of gridiview having webcontrols
问题描述
HI极客,
需要一些澄清。我正在使用一个没有行和列的gridview。
在页脚,我有一个按钮在gridview中添加新行。我的gridview包括输入控件,如radiobutton,文本框等。
我的疑问是:我在gridview的所有行中都有一个radiobuttonlist,当我点击listitem时radiobuttonlist,我需要知道为某些要求选择了哪一行(ROWINDEX)radiobuttonlist。
我用过这段代码
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
int rowIndex=gv.SelectedIndex;
我点击第5行的radiobutonlist,rowIndex返回-1。
你能帮助我们吗?
谢谢
I clicked the radiobutonlist at 5th row and rowIndex returns -1.
Can you help us?
Thanks
推荐答案
试试这个
try this
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;
}
这篇关于如何获取具有webcontrols的gridiview的当前rowindex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!