[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1739
  • Last Modified:

C# GRID Radio Buttons


Using C#

I've a little problem with a grid and radio. I've a grid with 3 columns. One of these columns has 2 Radiobutton (in a group). The last column has a button (Submit)
I bind the grid in C# code behind (including textbox, label and radio button).
Now the problem is I bind the grid and depends what line, the radio will be selected. So it will checked.
The grid fill when the page load!!

But after I bind the grid, I want to select any RADIO in any row and change the selection.
I tried to use IspostBack, but I can't use it because everytime I selected the radiobutton the page reload.
So if I'll change the radiobutton, the page reload, fill the grid again and I lost the selection, that the problem I've with ispostback

So in little words what I need is: I need to change the "checked" radiobutton WITHOUT reload the page.
Maybe using javascript onlick.
But the problem with this solution is: I can't use onlick in asp:radiobutton, because is not supported.

Please if anyone can help, I will really appreciate it!

1 Solution
I think your radiobuttons autopostback property set to true. change it to false.
and on click event your button inside gridview, cast sender object to button and get parent.parent for reeaching gridviewrow

private Button1_Click(object sender, EventArgs e)
 Button btn=(Button)sender;
 GrivewRow row=(GridViewRow)btn.Parent.Parent;
 RadioButton rd1=(RadioButton)row.FindControl("RadioButtonControlName1");
 RadioButton rd2=(RadioButton)row.FindControl("RadioButtonControlName2");
 //Do your reolad here
else if(rd2.Checked)
 //Do your reolad here

Open in new window

nkoriginalAuthor Commented:
Hello Monarch:

Thank you for your reply.
I tried the code you send me but nothing happened.

the problem is when I load the page, the grid fill all fields. (textbox, radiobutton).
I when the I bind the radio, I send by code behind radiobutton.checked = true.
So the radiobutton will be checked in the GridView1_RowDataBound.
After all this, the user wants to change that status in the radiobutton, but nothing happen because by default the radio is checked in one value, maybe I will need a java script code?

Thank you

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now