Click here to Skip to main content
15,898,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi one and all,

I need help. I have written a program regarding grid view with radio buttons.

Now what I need is if I did not select a radio box and click on delete button, I should get an alert like please select at least one.
If I select a radio box and click on delete, I would like to get an alert like Do you want to delete.

Can any one help me regarding this.

Thanks & Regards,
M.Dorababu
Posted
Updated 10-May-10 10:27am
v2

Got the required answer.
JavaScript
<script type="text/javascript">
function Validate() {  
var gv = document.getElementById("<%=GridView1.ClientID%>");  
var rbs = gv.getElementsByTagName("input");
            var flag = 0;  
for(var i=0; i < rbs.length; i++)
{
    if(rbs[i].type="radio")
    {
        if(rbs[i].checked)
        {
          flag=1;
          break;
        }
    }
}
  if(flag==0)
  {
    alert("Select one");
    return false;
  }
  else
  {
    return confirm('Are you sure you want to delete this record?');
  }
}
</script>

In page load write this

Button1.Attributes.Add("onclick", "javascript:return Validate()");

That's It
 
Share this answer
 
v2
Sounds like a homework question to me?

In the delete button click event, do a check of the radio button checked state and or them together, if any of the values true then the result will be true.

e.g.
Java
if !(radio1state || radio2state || radio3state)
{
 alert("The message")
}
 
Share this answer
 
Comments
Christian Graus 10-May-10 18:45pm    
I'd suspect more that it's someone who is underskilled, doing paid work in an outsourcing house.

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