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

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


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

let me know how it goes.


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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.