I can edit the data with the following code:
Expand|Select|Wrap|Line Numbers
- Public Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
- GridView1.EditIndex = e.NewEditIndex
- Call LoadGrid()
- Dim f1 As String = GridView1.Rows(e.NewEditIndex).Cells(1).Text
- Dim f2 As String = GridView1.Rows(e.NewEditIndex).Cells(2).Text
- Dim f3 As String = GridView1.Rows(e.NewEditIndex).Cells(3).Text
- lbl1.Text = f1
- lbl2.Text = f2
- lbl3.Text = f3
- ''Dim dc As TextBox = GridView1.Rows(e.NewEditIndex).Cells(1).FindControl("bdistcode")
- ''lblDn.Text = dc.Text
- End Sub
- Public Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
- If (Session("sid").ToString() = "d" Or Session("sid").ToString() = "s" Or Session("sid").ToString() = "b") Then
- Dim f1 As String = GridView1.Rows(e.RowIndex).Cells(1).Text
- Dim f2 As String = GridView1.Rows(e.RowIndex).Cells(2).Text
- Dim f3 As String = GridView1.Rows(e.RowIndex).Cells(3).Text
- Select Case (Session("sid").ToString())
- Case "d"
- constr = "update D set dc=@f1,dn_h=@f2 where dn=@f3"
- Case "s"
- constr = "update sd set sd_c=@f1,sd_nm=@f2 where id=@f3"
- Case "b"
- constr = "update bl set blc=@f1,bln=@f2 where id=@f3"
- End Select
- cmd = New SqlCommand(constr, con)
- Try
- If con.State = ConnectionState.Closed Then con.Open()
- cmd.Parameters.Clear()
- cmd.Parameters.Add(New SqlParameter("@f1", SqlDbType.NVarChar)).Value = f1.ToString()
- cmd.Parameters.Add(New SqlParameter("@f2", SqlDbType.NVarChar)).Value = f2.ToString()
- If (Session("sid").ToString() = "d") Then
- cmd.Parameters.Add(New SqlParameter("@f3", SqlDbType.VarChar)).Value = f3.ToString()
- Else
- cmd.Parameters.Add(New SqlParameter("@f3", SqlDbType.Int)).Value = Convert.ToInt32(f3)
- End If
- Dim rowno As Integer = cmd.ExecuteNonQuery()
- Catch ex As Exception
- lblMessage.Text = lblMessage.Text & "Error" & ex.Message & "Field Value f1="
- If con.State = ConnectionState.Open Then con.Close()
- Finally
- If con.State = ConnectionState.Open Then con.Close()
- End Try
- 'lblMessage.Text = "Record Updated Successfully"
- 'lblMessage.Visible = True
- GridView1.EditIndex = -1
- Call LoadGrid()
- End If
- End Sub