Foros del Web » Programación para mayores de 30 ;) » .NET »

Modo Edicion Datagrid

Estas en el tema de Modo Edicion Datagrid en el foro de .NET en Foros del Web. Hola, inserte 3 drops dentro de un datagrid, cada drop esta enlazado a una tabla de una base de datos Como hago para que estando ...
  #1 (permalink)  
Antiguo 15/03/2005, 11:07
Avatar de Sayra  
Fecha de Ingreso: diciembre-2004
Mensajes: 365
Antigüedad: 19 años, 5 meses
Puntos: 1
Modo Edicion Datagrid

Hola, inserte 3 drops dentro de un datagrid, cada drop esta enlazado a una tabla de una base de datos

Como hago para que estando en modo edicion cuando seleccione elementos de ese drop quede seleccionado cuando le update

yo lo estaba haciendo asi, pero me da error,

Sub MyDataGrid_Update(Sender As Object, E As DataGridCommandEventArgs)

If (Page.IsValid)
Dim DS As DataSet
Dim MyCommand As SqlCommand

Dim UpdateCmd As String = "UPDATE Agencia SET CodigoID = @CodigoID, Agencia = @Agencia, Direccion = @Direccion, Codigo_Area = @Codigo_Area, Telefono = @Telefono, Fax = @Fax, Estado = @Estado, Ciudad = @Ciudad, Ubicacion = @Ubicacion,Estacionamiento= @Estacionamiento, Cajero_Automatico= @Cajero_Automatico, Autobanco= @Autobanco,Taquilla_Externa= @Taquilla_Externa, where CodigoID = @CodigoID"

MyCommand = New SqlCommand(UpdateCmd, MyConnection)

MyCommand.Parameters.Add(New SqlParameter("@CodigoID", SqlDbType.NVarChar, 11))
MyCommand.Parameters.Add(New SqlParameter("@Agencia", SqlDbType.NVarChar, 40))
MyCommand.Parameters.Add(New SqlParameter("@Direccion", SqlDbType.NVarChar, 20))
MyCommand.Parameters.Add(New SqlParameter("@Codigo_Area", SqlDbType.NChar, 12))
MyCommand.Parameters.Add(New SqlParameter("@Telefono", SqlDbType.NVarChar, 40))
MyCommand.Parameters.Add(New SqlParameter("@Fax", SqlDbType.NVarChar, 40))
MyCommand.Parameters.Add(New SqlParameter("@Estado", SqlDbType.NVarChar, 20))
MyCommand.Parameters.Add(New SqlParameter("@Ciudad", SqlDbType.NChar, 2))
MyCommand.Parameters.Add(New SqlParameter("@Ubicacion", SqlDbType.NChar, 5))
MyCommand.Parameters.Add(New SqlParameter("@Estacionamiento", SqlDbType.NVarChar,1))
MyCommand.Parameters.Add(New SqlParameter("@Cajero_Automatico", SqlDbType.NVarChar,1))
MyCommand.Parameters.Add(New SqlParameter("@Autobanco", SqlDbType.NVarChar,1))
MyCommand.Parameters.Add(New SqlParameter("@Taquilla_Externa", SqlDbType.NVarChar,1))

MyCommand.Parameters("@CodigoID").Value = MyDataGrid.DataKeys(CInt(E.Item.ItemIndex))

Dim Cols As String() = {"Agencia","Direccion","Codigo_Area","Telefono","F ax", "Estacionamiento", "Cajero_Automatico", "Autobanco", "Taquilla_Externa"}

Dim I As Integer
For I = 0 To 10
Dim CurrentTextBox As TextBox
CurrentTextBox = E.Item.FindControl("edit_" & Cols(I))
Dim ColValue As String = CurrentTextBox.Text
MyCommand.Parameters("@" & Cols(I)).Value = ColValue

Next

Dim StateDropDownList As DropDownList
StateDropDownList = E.Item.FindControl("DropDownList4")
MyCommand.Parameters("@Estado").Value = StateDropDownList.SelectedItem.ToString()

Dim CityDropDownList As DropDownList
CityDropDownList = E.Item.FindControl("DropDownList5")
MyCommand.Parameters("@Ciudad").Value = CityDropDownList.SelectedItem.ToString()

Dim UbiDropDownList As DropDownList
UbiDropDownList = E.Item.FindControl("DropDownList6")
MyCommand.Parameters("@Ubicacion").Value = UbiDropDownList.SelectedItem.ToString()

MyCommand.Connection.Open()

Try
MyCommand.ExecuteNonQuery()
Message.InnerHtml = "<b>Registro actualizado</b><br>" & UpdateCmd
MyDataGrid.EditItemIndex = -1
Catch Exp As SqlException
If Exp.Number = 2627
Message.InnerHtml = "ERROR: ya existe un registro con la misma clave principal"
Else
Message.InnerHtml = "ERROR: no se pudo actualizar el registro, compruebe que los campos están rellenos correctamente"
End If
Message.Style("color") = "red"
End Try

MyCommand.Connection.Close()

BindGrid()
Else
Message.InnerHtml = "ERROR: compruebe las condiciones de error de cada campo."
Message.Style("color") = "red"
End If
End Sub



Sub BindGrid()

Dim DS As DataSet
Dim MyCommand As SqlDataAdapter
Dim strSql As String = "Select Agencia.CodigoID as CodigoID, Agencia.Agencia as Agencia, Agencia.Direccion as Direccion, Agencia.Codigo_Area as Codigo_Area, Agencia.Telefono as Telefono,Agencia.Fax as Fax, Agencia.Cajero_Automatico as Cajero_Automatico, Agencia.Autobanco as Autobanco, Agencia.Taquilla_Externa as Taquilla_Externa, Agencia.Estacionamiento as Estacionamiento, Estado.Nombre_Estado as Estado, Ciudad.Nombre_Ciudad as Ciudad, Ubicacion.Descripcion as Ubicacion From Agencia, Estado, Ciudad, Ubicacion"
strSql += " WHERE Agencia.EstadoID=Estado.EstadoID"
strSql += " AND Agencia.CiudadID=Ciudad.CiudadID"
strSql += " AND Agencia.UbicacionID=Ubicacion.UbicacionID"
MyCommand = new SqlDataAdapter(strSql, MyConnection)

DS = new DataSet()
MyCommand.Fill(DS, "Agencia")

MyDataGrid.DataSource=DS.Tables("Agencia").Default View
MyDataGrid.DataBind()
End Sub


El error que me da este

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:
Line 277: Dim ColValue As String = CurrentTextBox.Text
  #2 (permalink)  
Antiguo 15/03/2005, 13:29
Avatar de Sayra  
Fecha de Ingreso: diciembre-2004
Mensajes: 365
Antigüedad: 19 años, 5 meses
Puntos: 1
Cuando en el modo edicion le doy actualizar una vez que he midificado mis campos me da el siguiente

error aqui

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Line 271: Dim ColValue As String = CurrentTextBox.Text


a que puede deberse estoy?

gracias por la ayuda que pueden brindarme
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:31.