单击GridView中的单选按钮获取行索引 [英] Get Row Index on click of Radio Button in GridView

查看:100
本文介绍了单击GridView中的单选按钮获取行索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在C#中的一个项目中工作.在其中显示网格视图中的记录.
在gridview的一列中,我使用单选按钮,在下一列中,使用Textbox.
我希望当我选择单选按钮时,应启用该行中下一列的文本框.
我想获得单击了行单选按钮的gridview的rowindex.

如果有人知道,请告诉我代码.

Hello Every One,

I am working in a project in C#. In Which I am show records in gridview.
In a column of gridview i use a radio button and in next column one Textbox.
I want that when i select the radio button then Textbox of next column in that row should be enable.
I want to get the rowindex of gridview in which row radio button is clicked.

please tell me the code if any one know.

thanks in advance.

推荐答案

在"_CellContentClick"事件中键入此内容;
In the "_CellContentClick" event just type this;
int index = e.RowIndex;


尝试以下操作:
Try this:
protected void Button1_Click(object sender, EventArgs e)
{
    int Id = 0;
    foreach (GridViewRow row in GridView1.Rows)
    {
        RadioButton rb = (RadioButton)row.FindControl("RadioButton1");
        if (rb.Checked)
        {
            Id =Convert.ToInt32(GridView1.Rows[row.RowIndex].Cells[1].Text);
            //Add your code
        }
    }
}



请参考:在GridView中使用单选按钮 [ ^ ]



Please refer: Using a Radio Button in a GridView[^]


尝试一下:
aspx代码:
Try this:
aspx code:
<asp:GridView ID="gvItems" runat="server" AutoGenerateColumns="false"

    OnRowCommand="gvItems_RowCommand">
    <Columns>
        <asp:ButtonField ButtonType="Image" ImageUrl="~/radioButtonOFF.gif" CommandName="ibtnRadio" />
        <asp:BoundField HeaderText="Item" DataField="Name" />
    </Columns>
</asp:GridView>



cs代码:



cs code:

protected void gvItems_RowCommand(object sender, GridViewCommandEventArgs e)
{

    if (e.CommandName == "ibtnRadio")
    {
        int rowIndex = int.Parse(e.CommandArgument.ToString());
        //your code here
    }
}


看下面的链接
http://technico.qnownow.com/2012/05/07/radiobutton -in-asp-net-gridview/ [


Have look on following link
http://technico.qnownow.com/2012/05/07/radiobutton-in-asp-net-gridview/[^]


这篇关于单击GridView中的单选按钮获取行索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆