T have used checkbox column in gridview. On click of a linkbutton, it should be checked that checkboxes in gridview are checked or not. If none check box is checked then it should display alert("Check at leat one check box").
相关问题
- Is there a limit to how many levels you can nest i
- Sorting 3 numbers without branching [closed]
- How to toggle on Order in ReactJS
- Graphics.DrawImage() - Throws out of memory except
- Carriage Return (ASCII chr 13) is missing from tex
You will have to add some custom Javascript to your page for the client-side alert to show. Here's a method that I've written that works with a GridView called 'GridView1' (this should be the default name if you've just dragged the control onto your ASPX page):
You can see that it sets a variable to the
GridView
control to start with, then iterates through all the children in afor
loop. If the child is acheckbox
and it ischecked
, then we set thevalid
variable to true. If we get to the end of the iteration and no checked checkboxes are found, thenvalid
remains false and we execute the alert.To link this into your
GridView
on your ASPX page, first make the button column aTemplateField
and surround theLinkButton
with your client-side code. If you've used the designer to set up your columns, you can use the "Convert this field into a TemplateField" link in the column editor). Here's an example of the source you'll end up with:Using the
TemplateField
lets us add any client-side code we like. Here we're adding aspan
and usingonclick
to call ourClientCheck
method.If you aren't bothered about the alert, you could achieve your aims by using a
CustomValidator
control, which executes on the server-side.I hope this helps.
I havnt used the checkbox in grid view but would you not do a for loop around the columns in gridview and check the state? Myabe add a count and if 0 then alert.
I found the answer. and its working...
function checkBoxselectedornot() {
and girdview code is...
and there is a link button ....