?
Solved

update gridview row programmatically

Posted on 2011-03-08
3
Medium Priority
?
765 Views
Last Modified: 2012-05-11
I have an SQL 6.5 server database table. I need to update row this is my code
Public Sub BindGrid()
       
        Dim ds As DataSet = Regulated.GetRegulatedParameters
        Dim dtParams As DataTable = ds.Tables(0)

        Session("dtParams") = dtParams

        Gridview1.DataSource = Session("dtParams")
        Gridview1.DataBind()
    End Sub
Protected Sub Gridview1_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)

        Dim dt = CType(Session("dtParams"), DataTable).
        Dim row = Gridview1.Rows(e.RowIndex)
        dt.Rows(row.DataItemIndex)("ParameterId") = (CType(row.FindControl("lblParameterId"), Label)).Text
        dt.Rows(row.DataItemIndex)("ParamName") = (CType(row.FindControl("txtParamName"), TextBox)).Text
        dt.Rows(row.DataItemIndex)("mnemonic") = (CType(row.FindControl("txtmnemonic"), TextBox)).Text
        dt.Rows(row.DataItemIndex)("Condition1Min") = (CType(row.FindControl("txtCondition1Min"), TextBox)).Text
        dt.Rows(row.DataItemIndex)("Level1Min") = (CType(row.FindControl("txtLevel1Min"), TextBox)).Text
        dt.Rows(row.DataItemIndex)("Condition0Min") = (CType(row.FindControl("txtCondition0Min"), TextBox)).Text
        If (CType(row.FindControl("txtLevel0Min"), TextBox)).Text <> "" Then
            dt.Rows(row.DataItemIndex)("Level0Min") = (CType(row.FindControl("txtLevel0Min"), TextBox)).Text
        Else
            dt.Rows(row.DataItemIndex)("Level0Min") = DBNull.Value
        End If

        dt.Rows(row.DataItemIndex)("Condition0Max") = (CType(row.FindControl("txtCondition0Max"), TextBox)).Text
        If (CType(row.FindControl("txtLevel0Max"), TextBox)).Text <> "" Then
            dt.Rows(row.DataItemIndex)("Level0Max") = (CType(row.FindControl("txtLevel0Max"), TextBox)).Text
        Else
            dt.Rows(row.DataItemIndex)("Level0Max") = DBNull.Value
        End If
        dt.Rows(row.DataItemIndex)("Condition1Max") = (CType(row.FindControl("txtCondition1Max"), TextBox)).Text
        If (CType(row.FindControl("txtLevel1Max"), TextBox)).Text <> "" Then
            dt.Rows(row.DataItemIndex)("Level1Max") = (CType(row.FindControl("txtLevel1Max"), TextBox)).Text
        Else
            dt.Rows(row.DataItemIndex)("Level0Max") = DBNull.Value
        End If
       

        If (CType(row.FindControl("txtMCL"), TextBox)).Text <> "" Then
            dt.Rows(row.DataItemIndex)("Level1Max") = (CType(row.FindControl("txtMCL"), TextBox)).Text
        Else
            dt.Rows(row.DataItemIndex)("MCL") = DBNull.Value
        End If

        Gridview1.EditIndex = -1
        BindGrid()
    End Sub
I do not get any error messages but it does not update the record.
What am I doing wrong?

Thank you in advance

0
Comment
Question by:msout
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 13

Expert Comment

by:gamarrojgq
ID: 35073596
Hi,

You are getting your data from Regulated.GetRegulatedParameters, but when you Update the changes, you are updating the datatable in  Session("dtParams"), but after that you call agin the BindGrid SUB, so it gets agina the data from Regulated.GetRegulatedParameters, and since you have not update the data that Regulated.GetRegulatedParameters returns, you will get the same old data.

Your changes are just deleted.

You have to update your Datasource as well in order to get your code function well.

Or you can use Regulated.GetRegulatedParameters just the first time and wordk with Session("dtParmas") only, but it will depends on your application needs
0
 

Author Comment

by:msout
ID: 35074150
Wonderful!!!! Thank you!!!!
0
 
LVL 13

Accepted Solution

by:
gamarrojgq earned 2000 total points
ID: 35074271
Glad to help, don't forget to accept the solution
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month12 days, 23 hours left to enroll

777 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