update database via onclick event

craigmacca

Member
Joined
Sep 25, 2007
Messages
5
Programming Experience
Beginner
Hi i am new to .net and i have a template which loops through a gridview and deletes any items that are checked, with a onlick event

what i need to do is update a column to -1 instead of deleting.

can someone help me do this, been on this for 2 weeks now, and i cant see who to do it.

many thanks

VB.NET:
        For Each row As GridViewRow In GridView1.Rows
            ' Access the CheckBox
            Dim cb As CheckBox = row.FindControl("ProductSelector")
            If cb IsNot Nothing AndAlso cb.Checked Then
                ' Delete row! (Well, not really...)
                atLeastOneRowDeleted = True

                ' First, get the Sock_ID for the selected row
                Dim Sock_ID As Integer = _
                    Convert.ToInt32(GridView1.DataKeys(row.RowIndex).Value)

                ' "Delete" the row
                DeleteResults.Text &= String.Format( _
                    "This would have deleted ProductID {0}<br />", Sock_ID)



                '... To actually delete the product, use ...
                'Dim productAPI As New ProductsBLL
                'productAPI.UpdateProduct(Sock_ID)
                '............................................
            End If
        Next
 
Im not sure if I'm following you.

So you're using a asp.net datagrid, or is this windows form?

I normally like to work with the collection itself.

In any case if the code you posted is working for you, but you just want to delete a column by marking it something, then use

VB.NET:
row.FindControl("ColumnName") = -1

If this is not what you are looking for, then please clarify your question.
 
hi i am using a .net gridview.

i have a gridview that displays all item where Dispose = 0 from a MS Access database

one of the columns is a checkbox
when a onclick button is clicked this updates a YES/NO field to -1.

this updates the database fine now, but the page does not refresh with the correct data. as the items that were updated should not show.

i think i need a is post back but not sure how to do it?

many thanks
 
Last edited:
inserting gridview label into a table

ok that works i have one more problem if you could help.

i have a gridview, with labals and a checkbox.

i am looping through the gridview and inserting the id using the code below which works fine but now i need to insert other items from the current row.

and i am not sure how to do it, the bound column is called Stock_Code which i need to insert

VB.NET:
Dim Stock_ID As Integer = (GridView1.DataKeys(row.RowIndex).Value)
Dim Stock_Code As String = (GridView1?????????

Dim datap As New MainDataSetTableAdapters.BasketTableAdapter
datap.Insert(0, Stock_Code, 1, Stock_ID)
 
Back
Top