Row updating, row updated confusion

Okay this is the first time I've ever had to do code behind for row updating logic in a gridview. So be patient with me if it's totally incorrect.

Do I put the gridview rebind code in the Row Updating or Updated event?  Currently, I have it in both as I'm simply troubleshooting to try to get it to work.  With this code, not only is the record not updating but the record disappears from the gridview upon refreshing.

Protected Sub GridView2_RowUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdatedEventArgs) Handles GridView2.RowUpdated
        SqlDataSource1.SelectCommand = "SELECT [charge_rec_num], [statute], [statute] + ':' + [fciccodev] + '-' + [fsdesc] + '  ' + [chg_level] + '  ' + [count] as chargeinfo, [count] FROM [arrest_charges] WHERE ARRESTNO = '" & hdn_uid.Text & "'" & _
          " UNION ALL SELECT '','','','' FROM [arrest_charges] WHERE ARRESTNO = '" & hdn_uid.Text & "'" & " HAVING COUNT(charge_rec_num)=0"
        GridView2.DataBind()
    End Sub

Protected Sub GridView2_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView2.RowUpdating
        Dim ESOConnection, SmartCopConnection As SqlConnection
        Dim myquery As SqlCommand
        Dim mydatareader As SqlDataReader

        'open connection to esosql
        ESOConnection = New SqlConnection("server=esosql;database=eso_intranet;Initial Catalog=eso_intranet;uid=###;pwd=###")
        ESOConnection.Open()

        'open connection to smartcop.
        SmartCopConnection = New SqlConnection("server=eso-cad;database=cfg;MultipleActiveResultSets=True;uid=###;pwd=###")

        'open connection to smartcop
        SmartCopConnection.Open()
        myquery = New SqlCommand("SELECT FCICCODEV, FSDESC FROM FSS_AFIS WHERE FSN = @fsn", SmartCopConnection)

        Dim gvr As GridViewRow = GridView2.Rows(e.RowIndex)

        With myquery.Parameters
            .Add(New SqlParameter("@fsn", TryCast(gvr.FindControl("tx_statute"), TextBox).Text))
        End With

        mydatareader = myquery.ExecuteReader

        If mydatareader.HasRows Then

            mydatareader.Read()

            Dim cmd As New SqlCommand("UPDATE arrest_charges SET statute = @statute, fciccodev = @fciccodev, fsdesc = @fsdesc" & _
                " WHERE charge_rec_num = @charge_rec_num", ESOConnection)

            cmd.Parameters.AddWithValue("charge_rec_num", GridView2.DataKeys(e.RowIndex)("charge_rec_num"))
            cmd.Parameters.AddWithValue("statute", TryCast(gvr.FindControl("tx_statute"), TextBox).Text)
            cmd.Parameters.AddWithValue("fciccodev", mydatareader("fciccodev"))
            cmd.Parameters.AddWithValue("fsdesc", mydatareader("fsdesc"))
            cmd.Parameters.AddWithValue("count", TryCast(gvr.FindControl("textbox2"), TextBox).Text)

            cmd.ExecuteNonQuery()

            GridView2.EditIndex = -1

            SqlDataSource1.SelectCommand = "SELECT [charge_rec_num], [statute], [statute] + ':' + [fciccodev] + '-' + [fsdesc] + '  ' + [chg_level] + '  ' + [count] as chargeinfo, [count] FROM [arrest_charges] WHERE ARRESTNO = '" & hdn_uid.Text & "'" & _
                " UNION ALL SELECT '','','','' FROM [arrest_charges] WHERE ARRESTNO = '" & hdn_uid.Text & "'" & " HAVING COUNT(charge_rec_num)=0"
            GridView2.DataBind()
        End If

        ESOConnection.Close()
        SmartCopConnection.Close()

    End Sub

"Hey, how come pirates are so cool?"

"They just ARRRGGGHHHH!!!!!"
0
fralo
2/4/2009 4:12:42 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

1 Replies
801 Views

Similar Articles

[PageSpeed] 23

Please disregard.  This is resolved.  I had syntax issues in my aspx code which preventing my fields from being bound.


"Hey, how come pirates are so cool?"

"They just ARRRGGGHHHH!!!!!"
0
fralo
2/4/2009 4:53:25 PM
Reply:

Similar Artilces:

question about updating a row? How to update a different row.
I will try to make this as simple as I can. k, here I go. I originally populate my datagrid with data. Then during the edit mode, I can populate information by an ontextchanged event, which is actually bringing in a new row (essentially). My problem occurs when I try to update the data. Since the row was originally populated with the data, it updates that row in the table. But since I did an ontextchanged, I want to update that row instead. Not the original row. If I do an update, then I have two identical rows of data in my table, but with different primary keys. How can I update t...

update multi row when i meant update single row
RGVhciBhbGw6DQoNCkkgdHJpZWQgdG8gdXBkYXRlIGEgc2luZ2xlIHJvdyBmb3IgdGhlIGRh dGFiYXNlLCBob3dldmVyLCB0aGUgcXVlcnkgaGVyZQ0KdXBkYXRlIG11bHRpcGxlIHJvd3MN Cg0KbXkgJHNxbCA9ICJVUERBVEUgdXB0aW1lIFNFVCB1cF90aW1lPSRuZXdfdXB0aW1lDQog ICAgICAgICAgICAgV0hFUkUgaG9zdG5hbWUgPSAnJGhvc3QnIGFuZA0KICAgICAgICAgICAg IHN0YXJ0ZGF0ZT0gKHNlbGVjdCBNQVgoc3RhcnRkYXRlKSBmcm9tIHVwdGltZSB3aGVyZQ0K ICAgICAgICAgICAgIGhvc3RuYW1lID0nJGhvc3QnIGFuZCB1cF90aW1lID0gJG9sZHVwdGlt ZSkgIjsNCg0KSSBtZWFudCBvbmx5IHdhbnQgdG8gdXBkYXRlIGxhdGVzdCBzdGFydGRhdGUs IHNvbWVob3csIGl0IHJldHVybnMgYWxsDQp0aGUgc3RhcnRkYXRlIHdoaWNoIHVwX3RpbWUg PSRvbGR1...

warning: update row ... is a conflict update and this row is ignored
SQL Anywhere 10.0.1.3488 I am synching one SQL Anywhere database to another through MobiLink, getting this warning: W. 2008-08-19 13:01:01. <17> [10037] Ignoring updated row (new values) W. 2008-08-19 13:01:01. <17> [10038] Ignoring updated row (old values) W. 2008-08-19 13:01:01. <17> [10072] The update row for table '<orders>' is a conflict update and this row is ignored. There are currently no conflict resolution scripts in place, so I would expect the default behavior of "last one in wins" rather than seeing "this row is ign...

how to update a row using a seperate update button not command button without selecting the row?
How to update a row using a seperate update button not command button without selecting a row? Simple question but dificult to do. The reason I ask this is that when a user clicks 'Update' I want each row to update the database. Please note I can't use findcontrol as their are no headers This is my code so far: protected void UpdateButton_Click(object sender, EventArgs e){    foreach (GridViewRow row in CellGridView.Rows)     {          string stext = CellGridView.Rows.ToString();     &nb...

DataSet rows being deleted, but after the update , the sql database is not updated. The delete rows still in the database.
 Stepping thru the code with the debugger shows the dataset rows being deleted.   After executing the code, and getting to the page presentation. Then I stop the debug and start the page creation process again ( Page_Load ).    The database still has the original deleted dataset rows. Adding rows works, then updating works fine, but deleting rows, does not seem to work.   The dataset is configured to send the DataSet updates to the database. Use the standard wizard to create the dataSet.     cDependChildTA.Fill(cDependChildDs._ClientDependentC...

updates, updates, updates, NO MORE!
Name: Andreas Email: unbekanntatjokerdotms Product: Firefox Summary: updates, updates, updates, NO MORE! Comments: Hi ! if you want to develop a fine webbrowser, maybe you nee a new management. To release a new buggy version every two weeks is not very professional. Test your software before the release and let the user download a stable browser. this update-orgy since 2.0.0 used me to use Opera instead of FF. We haved use FF in our Company, but we can't deploy a new version every week to +200 Windows-clients, so in our company we've decided to return to IE, ...

updates, updates, updates
Name: hans jensen Email: hansjensen44_athotmaildotcom Product: Firefox Summary: updates, updates, updates Comments: why is it everytime i go online firefox has new updates, 3 -4 times every day, its never ending..........whats all the problems??? please email me and let me know, ty,.........Hans Jensen Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2 ...

Update Command Updates All Rows
I have a gridview update issue. I want to update just two fields "Email" and "IsLockedOut". However, when I press update all the rows are updated with the same information. I would like just the row that was in edit mode to be updated. My code is as follows:<asp:SqlDataSource ID="dbAdmin" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [vw_aspnet_MembershipUsers] ORDER BY [UserName]" OnSelecting="dbAdmin_Selecting" UpdateCommand="UPDATE as...

updates, updates, updates
Holy Crap, Batman! You'd think I was running Windows XP and it's patch Tuesday. So far this week - new kernel (2.6.27.10), 2 new browsers (Opera 9.63 and Firefox 3.05) and a new plugin (Flash 10.0.156.3). I'm about ready to try one od the BSD's! vince wrote: > Holy Crap, Batman! You'd think I was running Windows XP and it's patch > Tuesday. > > So far this week - new kernel (2.6.27.10), 2 new browsers (Opera 9.63 > and Firefox 3.05) and a new plugin (Flash 10.0.156.3). I'm about ready > to try one od the BSD's! I take ...

Updating DataList Row by Row
Hello, I have a datalist on my web page which displays a list of records from my database, all the information is displayed in labels except for one which is in a DropDownBox and the user can select Yes or No.  I want to update each record individual based on the value in the dropdownbox.  My problem is currently if I change the last record to say No then all the records in the db change to No.  It is not recording the new values row by row. Anybody got ideas why? ThanksRegards,Steven I don't think is the DataList because I used in that way myself many times Post som...

Updates, updates and more updates
Name: pirhan Email: pirhan_chanathotmaildotcom Product: Firefox Summary: Updates, updates and more updates Comments: Hello, Normally I use Safari, but my iBook is out of commission for a while. So, I am forced to use a PC to which I would much rather use Firefox than Internet Exploder. However, as much I enjoy not using a Microsoft product, and use a product that works decently, I am severely annoyed about the constant updates I am put through. In the last two days, I had to wait for Firefox to install updates before I could browse and now, I'm alerted that there'...

Updates Updates Updates
I was a big fan of Firefox.. Now, I don't even like to use it. Seems like every time I start it up I have to update some addin OR the browser itself. And unfortunately the update nag messages are always presented when I start a browsing session. I find this annoying because, typically, when I open a web browser all I want to do is go to a web page. Not update the browser. I can agree that staying current with the latest version could give the best, fastest, safest web experience. But that point becomes mute when I start off every other browsing session with a new update. And mos...

Updating only updated DataGrid rows
I have a gridview control that I have  swapped out the lable controls for textbox controls. What i want to do is code a save button to iterate through the rows and at any row where the value has been changed, run a sql update. I have the sql, I have the grid view, but i dont have the iteration code. (im using c#)psudo code:  while(gridview.rows.morerows()=true (or somthignlike that))if(row.current row.update = true ){do sql update here}nextRow Any hints are greately appreciated Dan    foreach (GridViewRow row in GridView1.Rows) { // You hav...

(Fwd) How to loop through a database, row by row, and select and update one row at a time
----- Forwarded message from Troy Mulder <mulderta@gmail.com> ----- Date: Mon, 12 Apr 2010 17:48:37 -0400 From: Troy Mulder <mulderta@gmail.com> To: Tim.Bunce@pobox.com Subject: How to loop through a database, row by row, and select and update one row at a time Hello Tim (is it Dr. Bunce?), My name is Troy Mulder, and I am trying to get a perl script to interface with a PostgreSQL database. I am trying to step through each row of the database, and read one column of the row, and update another column of the row. When I follow the online tutorial a...

Web resources about - Row updating, row updated confusion - asp.net.presentation-controls

Wikipedia talk:Updating information - Wikipedia, the free encyclopedia
This is brilliant! It would probably work best for elections etc in minor locations. For something that's well-known like a US predidential election, ...

8 Tools For Updating Facebook Offsite
Applications for receiving Facebook updates and notifications without having to keep the site open in a browser keep coming out. Here are eight ...

Updating how Cost per Click is Measured on Facebook
To help advertisers better understand how their ads perform, we're updating the definition of cost per click on Facebook. Learn what the change ...

Updating Your App for iOS 9: What You Need to Know
Updating Your App for iOS 9: What You Need to Know

Facebook for iPhone 3.0 to Include Page Updating
... who want to more easily update their Facebook Pages on the go: Facebook for iPhone 3.0 , which should be released soon, will include Page updating, ...

Updating trends on mobile
Trends are a great way to find out what people are talking about on Twitter at a given moment and at a single glance. Starting today, we’re making ...

Delhi Metro Fare Calculator and Auto-Updating Map on the App Store on iTunes
Get Delhi Metro Fare Calculator and Auto-Updating Map on the App Store. See screenshots and ratings, and read customer reviews.


Updating Emma: Jane Austen's classic joins list of literary reworks
Jane Austen published six novels. Just six. She died before she completed the seventh.

Tips For Updating Your Appearance
Like Joe Hockey, all men can pull off a radical mid-life makover by following some simple guidelines.

Resources last updated: 11/21/2015 9:27:41 AM