We're building a brand new version of the site, and we'd love to hear your ideas
Members
Technology Zones
IBM Learning Center
Articles
Hosted By
Info
|
[4632] Selecting, Confirming & Deleting Multiple Checkbox Items In A DataGrid (i.e. HotMail & Yahoo)
Last post 12-05-2006 7:02 AM by suhasini51. 57 replies.
-
Advertisement
|
|
-
-
DMarko1


- Joined on 09-19-2003

- Points 45
|
|
-
-
DMarko1


- Joined on 09-19-2003

- Points 45
|
|
-
-
DMarko1


- Joined on 09-19-2003

- Points 45
|
New Multi-Select Checkbox Article - Part II!
Hello all,
The article "Selecting, Confirming & Deleting Multiple Checkbox Items In A DataGrid" you may have read here on developerfusion is Part 1 written a while ago, and it covered only a simple example of checking a series of checkboxes within one page on a DataGrid, whereby you could then delete your items, but offered no paging nor any maintaining of state.
I have recently improved on this in Part 2 of the article, and it demonstrates how to multi-select checkboxes across pages with sorting on a page-by-page basis
You can find it on DNJ - Selecting, Confirming & Deleting Multiple Checkbox Items In A DataGrid - Part 2: Maintaining CheckBox State Across Pages with Sorting.
- Jimmy Markatos
|
|
-
-
-
Kaaron


- Joined on 10-08-2005

- Points 5
|
I am having trouble with the
Code:ClientScript.RegisterClientScriptBlock(Of Boolean, "jsScriptConfirmOption")()[\code]
I am using asp.net 2.0 and i found your code really useful. Unfortunately i dont know how to translate this one section of it.
I've changed the use of the code slightly from not having one delete button, but an accept button and a delete button. I need a different action for either button. the accept buttton updates and of couse the delete button deletes. can anyone tell me what the correct syntex
this is my code...
Code:Sub Page_PreRender(ByVal Sender As Object, ByVal E As EventArgs)
Dim nl As String = Environment.NewLine
Dim jsScriptConfirmOption As New StringBuilder()
With jsScriptConfirmOption
.Append("<script language=JavaScript>" & nl)
.Append("<!--" & nl & nl)
.Append("function confirmDelete (frm) {" & nl & nl)
.Append(" // loop through all elements" & nl & nl)
.Append(" for (i=0; i<frm.length; i++) {" & nl & nl)
.Append(" // Look for our checkboxes only" & nl)
.Append(" if (frm.elements.name.indexOf ('CHKOption') !=-1) {" & nl & nl)
.Append(" // If any are checked then confirm alert, otherwise nothing happens" & nl)
.Append(" if(frm.elements.checked) {" & nl & nl)
.Append(" return confirm ('Are you sure you want to delete your selection(s)?')" & nl & nl)
.Append(" }" & nl)
.Append(" }" & nl)
.Append(" }" & nl)
.Append(" }" & nl & nl)
.Append("function confirmAccept (frm) {" & nl & nl)
.Append(" // loop through all elements" & nl & nl)
.Append(" for (i=0; i<frm.length; i++) {" & nl & nl)
.Append(" // Look for our checkboxes only" & nl)
.Append(" if (frm.elements.name.indexOf ('CHKOption') !=-1) {" & nl & nl)
.Append(" // If any are checked then confirm alert, otherwise nothing happens" & nl)
.Append(" if(frm.elements.checked) {" & nl & nl)
.Append(" return confirm ('Are you sure you want to accept your selection(s)?')" & nl & nl)
.Append(" }" & nl)
.Append(" }" & nl)
.Append(" }" & nl)
.Append(" }" & nl & nl)
.Append("/*Using modified select_deselectAll script function of my original one,")
.Append(" from Developerfusion.com forum members - ketcapli & thombo")
.Append(" Forum Post - [http://www.developerfusion.co.uk/forums/topic-22773]*/")
.Append("function select_deselectAll (chkVal, idVal) {" & nl)
.Append(" var frm = document.forms[0];" & nl)
.Append(" if (idVal.indexOf('CHKOption') != -1 && chkVal == true){" & nl)
.Append(" var AllAreSelected = true;" & nl)
.Append(" for (i=0; i<frm.length; i++) {" & nl)
.Append(" if (frm.elements.id.indexOf('CHKOption') != -1 && frm.elements.checked == false){ " & nl)
.Append(" AllAreSelected = false;" & nl)
.Append(" break;" & nl)
.Append(" } " & nl)
.Append(" } " & nl)
.Append(" if(AllAreSelected == true){" & nl)
.Append(" for (j=0; j<frm.length; j++) {" & nl)
.Append(" if (frm.elements[j].id.indexOf ('CheckAll') != -1) {" & nl)
.Append(" frm.elements[j].checked = true;" & nl)
.Append(" break;" & nl)
.Append(" }" & nl)
.Append(" }" & nl)
.Append(" }" & nl)
.Append(" } else {" & nl)
.Append(" for (i=0; i<frm.length; i++) {" & nl)
.Append(" if (idVal.indexOf ('CheckAll') != -1) {" & nl)
.Append(" if(chkVal == true) {" & nl)
.Append(" frm.elements.checked = true; " & nl)
.Append(" } else {" & nl)
.Append(" frm.elements.checked = false; " & nl)
.Append(" }" & nl)
.Append(" } else if (idVal.indexOf('CHKOption') != -1 && frm.elements.checked == false) {" & nl)
.Append(" for (j=0; j<frm.length; j++) {" & nl)
.Append(" if (frm.elements[j].id.indexOf ('CheckAll') != -1) { " & nl)
.Append(" frm.elements[j].checked = false;" & nl)
.Append(" break; " & nl)
.Append(" } " & nl)
.Append(" } " & nl)
.Append(" } " & nl)
.Append(" } " & nl)
.Append(" } " & nl)
.Append(" } " & nl & nl)
.Append("//--> " & nl & nl)
.Append("</scr" & "ipt>")
End With
'Allows our .NET page to add client-side script blocks when page loads,
' instead of the conventional HTML JS tags.
If (Not ClientScript.IsClientScriptBlockRegistered("clientScript")) Then
ClientScript.RegisterClientScriptBlock(Of Boolean, "jsScriptConfirmOption")()
End If
jsScriptConfirmOption = Nothing
End Sub
|
|
-
-
-
-
-
-
-
Shafiqm


- Joined on 04-25-2006
- Canada

- Points 5
|
Re: [4632] Selecting, Confirming & Deleting Multiple Checkbox Items In A DataGrid (i.e. HotMail & Yahoo)
I like your article regarding checkboxes. I have very interesting situation, can you please help me how I can solve this.
My Gridview contains a template column which contains a checkboxlist control. Each row can have multiple checkboxes depening upon the data.
e.g (ALL, Code1, Code2, Code3 are checkboxes)
Row1 ALL Code1 Code2
Row2 ALL Code1
Row3 ALL Code1 Code2 Code3
How can I make sure that for each row, if user selects all the codes then ALL checbox will be automatically be checked and if only one code checbox is checked then ALL should not be checked. Please Guide, How I can achive this
Thanks
Shafiq
|
|
-
-
suhasini51


- Joined on 12-05-2006

- Points 5
|
Re: datagrid having multiple checkboxes with confirm d
Hi,
I required the same concept as in yahoomail.i am getting checkall and uncheckall in the grid.if all the items in the grid manually is checked then automatically the header checkbox should check.It is also completed.It's working fine.I took html checkboxes both in header and item level to call javascript functions so while deleting the id of that checkboxes is not coming in code behind to delete.if i take asp checkboxes,javascript function is not calling.And also i saw in most of the sites for asp checkbox there is onclick event calling javascript function but i am getting oncheckedchanged event only and not able to call javascript function in that.Please help me regarding this....
|
|
|
Search
Code Samples
New Members
|