add delete record checkbox to mxdatagrid

Posted on 2006-06-05
Last Modified: 2008-02-01

I'm stumped on how to add a "delete record" checkbox to a mxdatagrid. Any help is appreciated.

Question by:tnapolitano
    LVL 7

    Expert Comment

    You can add a checkbox column not bound to any fields, a delete button then loop through the gridviewrows and delete the records where the checkbox is checked.

    something like....
    foreach (GridViewRow row in gridView1.Rows) {
      CheckBox chk = (CheckBox)row.FindControl("chkBox1");
      if (chk.Checked) {
        //delete the record

    hope this helps.
    LVL 3

    Author Comment

    So here's what I did:

                        <wmx:TemplateField HeaderText="Delete">
                                <asp:checkbox id="active" runat="server" checked='<%# DataBinder.Eval(Container, "DataItem.Delete") %>' />
                        <wmx:BoundField DataField="Role" HeaderText="Role"></wmx:BoundField>
                        <wmx:BoundField DataField="Level" HeaderText="Level"></wmx:BoundField>
                        <wmx:BoundField DataField="Category" HeaderText="Category"></wmx:BoundField>
                        <wmx:BoundField DataField="Material" HeaderText="Material"></wmx:BoundField>
                        <wmx:BoundField DataField="Location" HeaderText="Location"></wmx:BoundField>
                        <wmx:BoundField DataField="Section" HeaderText="Section"></wmx:BoundField>

    Which gave me a checkbox column in my mxdatagrid. However when I try to compile/launch the page, I get:

    'System.Data.DataRowView' does not contain a property with the name Delete."

    How do I link the Checkbox to my function "delRecord"

     Function delRecord(ByVal uID As Integer) As Integer
            Dim connectionString As String = "server='(local)'; trusted_connection=true; database='Deputization'"
            Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString)

            Dim queryString As String = "DELETE FROM [dp_material] WHERE ([dp_material].[uID] = @uID)"
            Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand
            dbCommand.CommandText = queryString
            dbCommand.Connection = dbConnection

            Dim dbParam_uID As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
            dbParam_uID.ParameterName = "@uID"
            dbParam_uID.Value = uID
            dbParam_uID.DbType = System.Data.DbType.Int32

            Dim rowsAffected As Integer = 0
                rowsAffected = dbCommand.ExecuteNonQuery
            End Try

            Return rowsAffected
        End Function
    LVL 7

    Accepted Solution

    You are trying to bind the checkbox to a database field called 'Delete', which i am guessing you dont have in your initial databind.

    Are you trying to perform a single delete when a checkbox is checked? If so i recommend using a button, using a checkbox in this context i would expect to be able to select/deselect mulitple rows before commiting the delete.

    LVL 3

    Author Comment

    I'll give the button a try and get back to you.
    LVL 3

    Author Comment

    Yeah, a linkbutton was the way to go. Thanks.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now