943,832 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 4034
  • ASP.NET RSS
Dec 15th, 2008
0

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

Expand Post »
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
-mk- is offline Offline
10 posts
since Mar 2008
Dec 15th, 2008
0

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

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.....
Reputation Points: 33
Solved Threads: 10
Junior Poster in Training
4advanced is offline Offline
67 posts
since Nov 2008
Dec 16th, 2008
0

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

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.
ASP.NET Syntax (Toggle Plain Text)
  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
ASP.NET Syntax (Toggle Plain Text)
  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. }

ASP.NET Syntax (Toggle Plain Text)
  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. }
Reputation Points: 25
Solved Threads: 18
Practically a Master Poster
binoj_daniel is offline Offline
645 posts
since Dec 2006
Dec 16th, 2008
0

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

Thanks you guys !!!

I will go and try them out soon !!

Thanks..
Reputation Points: 10
Solved Threads: 0
Newbie Poster
-mk- is offline Offline
10 posts
since Mar 2008
Dec 16th, 2008
0

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

You can read more ASP.NET articles on coderewind.com

let me know how it goes.
Reputation Points: 25
Solved Threads: 18
Practically a Master Poster
binoj_daniel is offline Offline
645 posts
since Dec 2006
Dec 16th, 2008
0

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

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 !!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
-mk- is offline Offline
10 posts
since Mar 2008
Dec 17th, 2008
0

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

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.
Reputation Points: 25
Solved Threads: 18
Practically a Master Poster
binoj_daniel is offline Offline
645 posts
since Dec 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: checkbox query
Next Thread in ASP.NET Forum Timeline: Update record Problem.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC