Click here to Skip to main content
15,879,053 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted

In the "_CellContentClick" event just type this;
C#
int index = e.RowIndex;
 
Share this answer
 
v2
Comments
Prasad_Kulkarni 25-May-12 3:59am    
My 5! :)
ZaiDz 25-May-12 20:52pm    
Haha, thanks.
ZaiDz 25-May-12 20:52pm    
Smart move.
Try this:
C#
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
        }
    }
}


Please refer: Using a Radio Button in a GridView[^]
 
Share this answer
 
v2
Comments
coolnavjot31 25-May-12 1:31am    
Hi Prasad,

I use ur code it is working for me

thanks!
Prasad_Kulkarni 25-May-12 1:43am    
Glad it helps!
You're welcome.
ZaiDz 25-May-12 1:35am    
Don't want to be rude to Prasad but doesn't my solution work a lot better?
Prasad_Kulkarni 25-May-12 1:47am    
Still it sounds rude :)
Yes it will work, but you need to give detailed answer considering OP doesn't knows anything.

A lot better
How you consider this on result of your problem? or anything else..
ZaiDz 25-May-12 1:52am    
Idk
It just seems like it would be easier to understand and just more efficient.

Less code and it just seems like the proper way...

Idk lol, Sorry I just thought that that was the best way to do it.
Try this:
aspx code:
XML
<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 code:
C#
protected void gvItems_RowCommand(object sender, GridViewCommandEventArgs e)
{

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

Have look on following link
http://technico.qnownow.com/2012/05/07/radiobutton-in-asp-net-gridview/[^]
 
Share this answer
 
Comments
Prasad_Kulkarni 19-Jul-12 4:52am    
My 5!
in .cs file add this code on gridView_rowdataBound event
protected void Grv_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
RadioButton Rdn = (RadioButton)e.row.FindControl("RadioButton1");
TextBox Txt = (TextBox)e.row.FindControl("TextBox1");

Rdn.Row.Attributes.Add("onclick", "RdnClick(" + e.Row.RowIndex + "," + Txt.ClientID + ");");

}
}


in js write this script

function RdnClick(idx,Txt)
{
alert('Row index of gridview is :-' + idx)
Txt.disabled=false; // for enable text box of particular row
}
 
Share this answer
 

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