Click here to Skip to main content
14,271,278 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 2

Got the required answer.
<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
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
if !(radio1state || radio2state || radio3state)
{
 alert("The message")
}
   
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100