Radio button is not funtioning
Posted
by
user3614421
on Stack Overflow
See other posts from Stack Overflow
or by user3614421
Published on 2014-05-27T03:21:46Z
Indexed on
2014/05/27
3:25 UTC
Read the original article
Hit count: 132
ASP.NET
I'm having problem with my radio button in my gridview. I want to select any row one by one so that I can perform UPDATE, DELETE, and DISPLAY the row. When I select the button, the page will be refreshed and the button I selected before is not selected anymore. So I can't click any menu to update, delete or display the row. I noticed this is happening when I set the Autopostback = "True".
How can I solve it? Any idea? Below are my codes:
Page:
<script language="javascript" type="text/javascript">
function radiobtn(id) {
var rdBtn = document.getElementById(id);
var List = document.getElementsByTagName("input");
for (i = 0; i < List.length; i++) {
if (List[i].type == "radio" && List[i].id != rdBtn.id) {
List[i].checked = false;
}
}
}
</script>
<asp:RadioButton ID="CheckDel" runat="server" onclick="javascript:radiobtn(this.id)" OnCheckedChanged="CheckDel_CheckedChanged"
AutoPostBack="True" />
server end:
protected void CheckDel_CheckedChanged(object sender, EventArgs e)
{
CheckBox chkStatus = (CheckBox)sender;
GridViewRow row = (GridViewRow)chkStatus.NamingContainer;
Session["datestart"] = row.Cells[1].Text;
Session["empid"] = row.Cells[2].Text;
Session["empname"] = row.Cells[3].Text;
Session["days"] = row.Cells[4].Text;
Session["leavetype"] = row.Cells[5].Text;
Session["leavestatus"] = row.Cells[6].Text;
bool status = chkStatus.Checked;
}
Please help
© Stack Overflow or respective owner