Click here to Skip to main content
15,889,034 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
[edit]Delete all the "what do these do?" button presses, and what do we find? No question... - OriginalGriff[/edit]
Posted
Updated 7-Mar-11 8:32am
v2
Comments
OriginalGriff 7-Mar-11 14:32pm    
Did you want to ask a question?
Or just waste your time, and ours?

1 solution

What's the question i did't get you elaborate Clearly So that we can give you solution
If you want update a record in grid view
1.Do AutoGenerateEditButton make it true
2. Grid View Events OnRowEditing,OnRowUpdating,onRowEditCancel write Queries in these three events
Do it you got some idea
hope this helps you.
 
Share this answer
 
Comments
Member 3042184 7-Mar-11 15:47pm    
Thank you! This is my code. And it does not update!?
Public Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)

Dim connectionString As String = ConfigurationManager.ConnectionStrings("LIMS_ODBC").ConnectionString
Dim dbConnection As New Odbc.OdbcConnection(connectionString)
Dim cmd As New OdbcCommand
With cmd
cmd.CommandType = CommandType.Text
cmd.CommandText = "UPDATE Regulated " & _
"SET " & _
"ParamName = @ParamName , " & _
"mnemonic = @mnemonic , " & _
"Condition1Min =@Condition1Min, " & _
"Level1Min = @Level1Min , " & _
"Condition0Min = @Condition0Min, " & _
"Level0Min = @Level0Min, " & _
"Condition0Max = @Condition0Max , " & _
"Level0Max =@Level0Max, " & _
"Condition1Max = @Condition1Max, " & _
"Level1Max =@Level1Max, " & _
"MCL = @MCL " & _
"WHERE ParameterID = @ParameterId"


cmd.Parameters.AddWithValue("@ParamName", OdbcType.Char).Value = GridView1.Rows(e.RowIndex).FindControl("ParamName")
cmd.Parameters.AddWithValue("@mnemonic", OdbcType.Char).Value = GridView1.Rows(e.RowIndex).FindControl("mnemonic")
cmd.Parameters.AddWithValue("@Condition1Min", OdbcType.Char).Value = GridView1.Rows(e.RowIndex).FindControl("Condition1Min")
cmd.Parameters.AddWithValue("@Level1Min", OdbcType.Double).Value = GridView1.Rows(e.RowIndex).FindControl("Level1Min")
cmd.Parameters.AddWithValue("@Condition0Min", OdbcType.Char).Value = GridView1.Rows(e.RowIndex).FindControl("Condition0Min")
cmd.Parameters.AddWithValue("@Level0Min", OdbcType.Double).Value = GridView1.Rows(e.RowIndex).FindControl("Level0Min")
cmd.Parameters.AddWithValue("@Condition0Max", OdbcType.Char).Value = GridView1.Rows(e.RowIndex).FindControl("Condition0Max")
cmd.Parameters.AddWithValue("@Level0Max", OdbcType.Double).Value = GridView1.Rows(e.RowIndex).FindControl("Level0Max")
cmd.Parameters.AddWithValue("@Condition1Max", OdbcType.Char).Value = GridView1.Rows(e.RowIndex).FindControl("Condition1Max")
cmd.Parameters.AddWithValue("@Level1Max", OdbcType.Double).Value = GridView1.Rows(e.RowIndex).FindControl("level1Max")
cmd.Parameters.AddWithValue("@MCL", OdbcType.Double).Value = GridView1.Rows(e.RowIndex).FindControl("MCL")

End With
GridView1.EditIndex = -1
BindGrid()
End Sub
Member 3042184 8-Mar-11 12:27pm    
I use database SQL6.5 and VS2010 express. This code does not work.
I use another one now
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
It does not give an error
But it does not update.
tulasiram3975 10-Mar-11 3:22am    
Make Sure Do Not Bind Data to Grid View Before RowUpdating Block
BindGrid() This Method Will Run After RowUpdating Block
Check In Page_Load BindGrid() --> Call This Method Page Is Not Post Back Only

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900