Posted By

systemergon on 02/11/16


Tagged

registro actualizar GridView RowUpdating


Versions (?)

RowUpdating GridView


 / Published in: VB.NET
 

Dim IDVentas As String = GvVentas.Rows(e.RowIndex).Cells(1).Text() Dim FCH As String = DirectCast(GvVentas.Rows(e.RowIndex).FindControl("TXTFch"), TextBox).Text

  1. --- VISTA DISEÑO -----
  2.  
  3. <asp:GridView runat="server" ID="GvVentas" DataKeyNames="ID" OnRowUpdating="GvVentas_RowUpdating"
  4. OnSelectedIndexChanging ="GvVentas_SelectedIndexChanging" OnRowEditing ="GvVentas_RowEditing" AutoGenerateColumns="False" OnRowCancelingEdit="GvVentas_RowCancelingEdit">
  5.  
  6. <Columns>
  7. <asp:CommandField HeaderText="Edit-Update" ShowEditButton="True" />
  8.  
  9. <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="true" />
  10. <asp:BoundField DataField="TIE" HeaderText="TIE" ReadOnly="true"/>
  11. <asp:BoundField DataField="CREDITO" HeaderText="CREDITO" ReadOnly="true" />
  12. <asp:BoundField DataField="CONTADO" HeaderText="CONTADO" ReadOnly="true" />
  13. <asp:BoundField DataField="TOTAL" HeaderText="TOTAL" ReadOnly="true" />
  14. <asp:TemplateField HeaderText="FCH" SortExpression="FCH">
  15. <ItemTemplate>
  16. <asp:Label ID="LBFch" runat="server" Text='<%# Bind("FCH") %>'></asp:Label>
  17. </ItemTemplate>
  18. <EditItemTemplate>
  19. <asp:TextBox ID="TXTFch" runat="server" Text='<%# Bind("FCH") %>'></asp:TextBox>
  20. </EditItemTemplate>
  21. </asp:TemplateField>
  22.  
  23.  
  24.  
  25. </Columns>
  26. <RowStyle BackColor="#E3EAEB" />
  27. </asp:GridView>
  28.  
  29. --- CODIGO SERVIDOR----
  30.  
  31. Protected Sub GvVentas_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
  32. Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings("CadSQL").ToString())
  33. Dim cmd As New SqlCommand()
  34. cmd.Connection = cn
  35. cmd.CommandText = "UPDATE VENTDA SET FCH = @FCH WHERE ID = @ID"
  36. cmd.CommandType = CommandType.Text
  37. Dim IDVentas As String = GvVentas.Rows(e.RowIndex).Cells(1).Text()
  38. Dim FCH As String = DirectCast(GvVentas.Rows(e.RowIndex).FindControl("TXTFch"), TextBox).Text
  39. cmd.Parameters.Add("@ID", SqlDbType.Int).Value = IDVentas
  40. cmd.Parameters.Add("@FCH", SqlDbType.Date).Value = FCH
  41. cn.Open()
  42. cmd.ExecuteNonQuery()
  43. cn.Close()
  44. cn.Dispose()
  45. End Using
  46. GvVentas.EditIndex = -1
  47. BindData("B")
  48. End Sub

Report this snippet  

You need to login to post a comment.