Ver Mensaje Individual
  #2 (permalink)  
Antiguo 10/02/2006, 06:32
Martincho
 
Fecha de Ingreso: mayo-2002
Mensajes: 92
Antigüedad: 22 años, 8 meses
Puntos: 0
Codigo

Hola, paso el codigo, xq aun no puedo saber que hago mal, por favor estoy empezando y los tiempos se van acabando, tome el riesgo de hacer un desarrollo en asp.NET y por ahora no pude empezar a programar. Desde ya muchas gracias.-

Script:

Sub Page_Load(Sender As Object, E As EventArgs)
BindGrid()
End Sub

Sub MyDataGrid_Edit(Sender As Object, E As DataGridCommandEventArgs)
MyDataGrid.EditItemIndex =cint(E.Item.ItemIndex)
MyDataGrid.DataBind()
End Sub

Sub MyDataGrid_Cancel(Sender As Object, E As DataGridCommandEventArgs)
MyDataGrid.EditItemIndex = -1
MyDataGrid.DataBind()
BindGrid()
End Sub


Sub MyDataGrid_Update(Sender As Object, E As DataGridCommandEventArgs)

DIM MyConnection1 As New sqlConnection( "Data Source=localhost;Initial Catalog=mediterraneo;User Id=net;Password=net;" )
Dim MyCommand As SqlCommand
Dim UpdateCmd As String = "UPDATE clientes SET razon_social ='nuevo' where id_cli=" & MyDatagrid.DataKeys(CType(E.Item.ItemIndex, string))

MyCommand = New SqlCommand(UpdateCmd, MyConnection1)
Dim rowsAffected As Integer = 0
MyConnection1.open
Try
rowsAffected =MyCommand.ExecuteNonQuery()
Finally
MyConnection1.CLOSE
End Try

MyDatagrid.EditItemIndex = -1

BindGrid()
END SUB


Sub BindGrid()
Dim SelectCommand As String = "select id_cli,razon_social,tel from clientes"
myConnection = New sqlConnection( "Data Source=localhost;Initial Catalog=mediterraneo;User Id=net;Password=net;" )
MyCommand = New SqlDataAdapter(SelectCommand, MyConnection)
DS = new DataSet()
MyCommand.Fill(DS, "clientes")

MyDataGrid.DataSource=DS.Tables("clientes").Defaul tView
MyDataGrid.DataBind()
End Sub


Esta es la Declaracion del DataGrid(sin las etiquetas de diseño):

<ASP:DataGrid id="MyDataGrid" runat="server" OnEditCommand="MyDataGrid_Edit" OnCancelCommand="MyDataGrid_Cancel" OnUpdateCommand="MyDataGrid_Update" DataKeyField="id_cli" AutoGenerateColumns="False" EnableViewState="False">
<Columns><asp:EditCommandColumn CancelText="Cancel" UpdateText="Update" EditText="Edit"></asp:EditCommandColumn>
<asp:BoundColumn DataField="id_cli" HeaderText="id_cli" SortExpression="id_cli" ReadOnly="True"></asp:BoundColumn>
<asp:BoundColumn DataField="razon_social" HeaderText="razon_social" SortExpression="razon_social"></asp:BoundColumn>
<asp:BoundColumn DataField="tel" HeaderText="tel" SortExpression="tel"></asp:BoundColumn>
</Columns>
</ASP:DataGrid>

Saludos.-