How to create Check Box Controls list in Repeater/Datalist/Listview ??

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2008
Posts: 10
Reputation: -mk- is an unknown quantity at this point 
Solved Threads: 0
-mk- -mk- is offline Offline
Newbie Poster

How to create Check Box Controls list in Repeater/Datalist/Listview ??

 
0
  #1
Dec 15th, 2008
Hi,

I want to create a web application that have messaging feature,
thus the message inbox will be similar to typical email inbox where you can tick the checkboxes to select which email to be deleted or moved. Just like the below picture :

http://img209.imageshack.us/img209/7720/chkboxrj0.jpg

How do i create the checkbox inside the repeater/datalist/listview ??

and How to delete only the checked row ??

and lastly, I would like to add the master checkbox where when it is checked, it will check and select all the rows in that page.

Thanks for all suggestion and inputs !!
Last edited by -mk-; Dec 15th, 2008 at 4:52 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 63
Reputation: 4advanced is an unknown quantity at this point 
Solved Threads: 10
4advanced 4advanced is offline Offline
Junior Poster in Training

Re: How to create Check Box Controls list in Repeater/Datalist/Listview ??

 
0
  #2
Dec 15th, 2008
Create a templatefield, insert the checkbox and afterwards, check with FindControl() wether the checkbox has been checked. The mastercheckbox needs to be inserted in the headerrow of the control. Also there can be checked with FindControl(). If it's checked, reload the page. Be aware that the controls need to have AutoPostback() setted to true.

If you dont want it with autopostback you need to implement some literals and javascript which is harder to fix.....
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 645
Reputation: binoj_daniel is an unknown quantity at this point 
Solved Threads: 17
binoj_daniel's Avatar
binoj_daniel binoj_daniel is offline Offline
DaniWeb Expert

Re: How to create Check Box Controls list in Repeater/Datalist/Listview ??

 
0
  #3
Dec 16th, 2008
Here is the code sample with a GridView named "gv_Lookup"

//Place this on the aspx markup page for the GridView control to show the delete checkboxes on each row and the delete button in the footer.
  1. <asp:TemplateField HeaderText="Delete" ShowHeader="False" ItemStyle-HorizontalAlign="Center">
  2. <ItemTemplate>
  3. <asp:CheckBox ID="chkDeleteRows" runat="server"/>
  4. </ItemTemplate>
  5. <FooterTemplate>
  6. <asp:LinkButton ID="lbDelete" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete"></asp:LinkButton>
  7. </FooterTemplate>
  8. </asp:TemplateField>

// Set the OnRowDeleting property of the GridView
OnRowDeleting="gv_Lookup_RowDeleting"
// This method will be called on the click of the delete button. Defined later in the code sample

// Add this to generate the verification message
  1.  
  2. protected void gv_Lookup_RowDataBound(object sender, GridViewRowEventArgs e)
  3. {
  4. LinkButton lbDelete = (LinkButton)e.Row.FindControl("lbDelete");
  5. if (lbDelete != null)
  6. {
  7. lbDelete.Attributes.Add("onClick", "return confirm('Are you sure, you want to delete this Lookup Value? ');");
  8. }
  9. }

  1.  
  2. protected void gv_Lookup_RowDeleting(object sender, GridViewDeleteEventArgs e)
  3. {
  4. // Looping through all the rows in the GridView
  5. foreach (GridViewRow row in gv_Lookup.Rows)
  6. {
  7. CheckBox checkbox = (CheckBox)row.FindControl("chkDeleteRows");
  8. //Check if the checkbox is checked.
  9. if (checkbox.Checked)
  10. {
  11. // Pass the Row ID as parameter to your custom Delete Function
  12. DeleteLookupValues(Convert.ToInt32(gv_Lookup.DataKeys[row.RowIndex].Values[0]));
  13. }
  14. }
  15. LoadGrid(); // Refreshes the Grid with updated rows.
  16. }
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 10
Reputation: -mk- is an unknown quantity at this point 
Solved Threads: 0
-mk- -mk- is offline Offline
Newbie Poster

Re: How to create Check Box Controls list in Repeater/Datalist/Listview ??

 
0
  #4
Dec 16th, 2008
Thanks you guys !!!

I will go and try them out soon !!

Thanks..
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 645
Reputation: binoj_daniel is an unknown quantity at this point 
Solved Threads: 17
binoj_daniel's Avatar
binoj_daniel binoj_daniel is offline Offline
DaniWeb Expert

Re: How to create Check Box Controls list in Repeater/Datalist/Listview ??

 
0
  #5
Dec 16th, 2008
You can read more ASP.NET articles on coderewind.com

let me know how it goes.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 10
Reputation: -mk- is an unknown quantity at this point 
Solved Threads: 0
-mk- -mk- is offline Offline
Newbie Poster

Re: How to create Check Box Controls list in Repeater/Datalist/Listview ??

 
0
  #6
Dec 16th, 2008
hi,

i have tried the codes, and i got this error which i cant solve it.

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Any ideas ??

Thanks alot !!
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 645
Reputation: binoj_daniel is an unknown quantity at this point 
Solved Threads: 17
binoj_daniel's Avatar
binoj_daniel binoj_daniel is offline Offline
DaniWeb Expert

Re: How to create Check Box Controls list in Repeater/Datalist/Listview ??

 
0
  #7
Dec 17th, 2008
Put a breakpoint and see where exactly is the error. And also make sure you have the proper code in the Markup page also to the call the Grid Event.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC