?
Solved

add delete record checkbox to mxdatagrid

Posted on 2006-06-05
5
Medium Priority
?
266 Views
Last Modified: 2008-02-01

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

0
Comment
Question by:tnapolitano
  • 3
  • 2
5 Comments
 
LVL 7

Expert Comment

by:osiris247
ID: 16836578
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.
Steve
0
 
LVL 3

Author Comment

by:tnapolitano
ID: 16837559
So here's what I did:

                <Fields>
                    <wmx:TemplateField HeaderText="Delete">
                        <ItemTemplate>
                            <asp:checkbox id="active" runat="server" checked='<%# DataBinder.Eval(Container, "DataItem.Delete") %>' />
                        </ItemTemplate>
                    </wmx:TemplateField>
                    <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>
                </Fields>
            </wmx:MxDataGrid>

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
        dbCommand.Parameters.Add(dbParam_uID)

        Dim rowsAffected As Integer = 0
        dbConnection.Open
        Try
            rowsAffected = dbCommand.ExecuteNonQuery
        Finally
            dbConnection.Close
        End Try

        Return rowsAffected
    End Function
0
 
LVL 7

Accepted Solution

by:
osiris247 earned 1000 total points
ID: 16837607
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.

Steve
0
 
LVL 3

Author Comment

by:tnapolitano
ID: 16838926
I'll give the button a try and get back to you.
0
 
LVL 3

Author Comment

by:tnapolitano
ID: 16844453
Yeah, a linkbutton was the way to go. Thanks.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net 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…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Loops Section Overview
Suggested Courses
Course of the Month17 days, 13 hours left to enroll

829 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