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 :


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 !!

8 Years
Discussion Span
Last Post by binoj_daniel

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.....


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:TemplateField HeaderText="Delete" ShowHeader="False" ItemStyle-HorizontalAlign="Center">
                            <asp:CheckBox ID="chkDeleteRows" runat="server"/>
                          <asp:LinkButton ID="lbDelete" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete"></asp:LinkButton>                                               

// Set the OnRowDeleting property of the GridView
// 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

protected void gv_Lookup_RowDataBound(object sender, GridViewRowEventArgs e)
            LinkButton lbDelete = (LinkButton)e.Row.FindControl("lbDelete");
            if (lbDelete != null)
                lbDelete.Attributes.Add("onClick", "return confirm('Are you sure, you want to delete this Lookup Value? ');");
protected void gv_Lookup_RowDeleting(object sender, GridViewDeleteEventArgs e)
            // Looping through all the rows in the GridView
            foreach (GridViewRow row in gv_Lookup.Rows)
                CheckBox checkbox = (CheckBox)row.FindControl("chkDeleteRows");
                //Check if the checkbox is checked. 
                if (checkbox.Checked)
                    // Pass the Row ID as parameter to your custom Delete Function
            LoadGrid(); // Refreshes the Grid with updated rows.

Thanks you guys !!!

I will go and try them out soon !!




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 !!


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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.