In the gridview radiobutton column, if we need to select a single radio button as a single option then we need to do some javascript for that...
JavaScript for single select radio button:
<script type="text/javascript">
function RadioChecked(param)
{
var frm = document.forms[0];
for (i=0; i < frm.length; i++)
{
if (frm.elements[i].type == "radio")
{
if (param != frm.elements[i].id )
{
frm.elements[i].checked = false;
}
}
}
}
function RadioChecked(param)
{
var frm = document.forms[0];
for (i=0; i < frm.length; i++)
{
if (frm.elements[i].type == "radio")
{
if (param != frm.elements[i].id )
{
frm.elements[i].checked = false;
}
}
}
}
</script>
Code behind:
protected void YourGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex != -1 && e.Row.DataItem != null)
{
//calling javascript function to restrict the user to select only one radiobutton
RadioButton rd = (RadioButton)e.Row.FindControl("rdbGVRow");
rd.Attributes.Add("onclick", "javascript:RadioChecked('" + rd.ClientID + "');");
}
{
if (e.Row.RowIndex != -1 && e.Row.DataItem != null)
{
//calling javascript function to restrict the user to select only one radiobutton
RadioButton rd = (RadioButton)e.Row.FindControl("rdbGVRow");
rd.Attributes.Add("onclick", "javascript:RadioChecked('" + rd.ClientID + "');");
}
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.