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

Drop y datagrid

Estas en el tema de Drop y datagrid en el foro de .NET en Foros del Web. Muchachos ya consegui insertar un dropdownlist dentro de un datagrid La cosa es que no cuando intento enlazar ese drop a su a una tabla ...
  #1 (permalink)  
Antiguo 14/03/2005, 15:39
Avatar de Sayra  
Fecha de Ingreso: diciembre-2004
Mensajes: 365
Antigüedad: 19 años, 5 meses
Puntos: 1
Drop y datagrid

Muchachos ya consegui insertar un dropdownlist dentro de un datagrid
La cosa es que no cuando intento enlazar ese drop a su a una tabla de la base de datos me da error
lo estoy haciendo asi

Sub Estado ()
Dim ds As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter

ds = New DataSet ()
MyConnection = New SqlConnection("SERVER=MDS01; DATABASE=be; INTEGRATED SECURITY=false;PASSWORD=sa;USER=sa")

MyCommand = New SqlDataAdapter ("select EstadoID, Nombre_Estado from Estado" , MyConnection)
MyCommand.Fill(ds,"Estado")

DropDownList1.DataSource = ds.Tables("Estado").DefaultView
DropDownList1.DataTextField = "Nombre_Estado"
DropDownList1.DataValueField ="EstadoID"
DropDownList1.DataBind()
DropDownList1.Items.Insert(0, "Seleccione un item")
DropDownList1.SelectedIndex = 0
end sub
y drop dentro del grid
asi
<asp:TemplateColumn HeaderText="EstadoID" SortExpression="EstadoID">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "EstadoID") %>' ID="Label6" NAME="Label6"/>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList autopostback ="True" runat="server" id="DropDownList1">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>


Auxilio por favor necesito enlazarlo con la fuente de datos
Un millon de garcias por la asistencia
  #2 (permalink)  
Antiguo 14/03/2005, 15:48
Avatar de RootK
Moderador
 
Fecha de Ingreso: febrero-2002
Ubicación: México D.F
Mensajes: 8.004
Antigüedad: 22 años, 3 meses
Puntos: 50
Sería algo así:

Cita:
Function Estado () as DataSet
Dim ds As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter

ds = New DataSet ()
MyConnection = New SqlConnection("SERVER=MDS01; DATABASE=be; INTEGRATED SECURITY=false;PASSWORD=sa;USER=sa")

MyCommand = New SqlDataAdapter ("select EstadoID, Nombre_Estado from Estado" , MyConnection)
MyCommand.Fill(ds,"Estado")

return ds

End Function
...
...
<EditItemTemplate>
<asp:DropDownList autopostback ="True" runat="server" id="DropDownList1" DataSource='<%# Estado() %>' DataValueField="EstadoID" DataTextField="Nombre_Estado">
</asp:DropDownList>
</EditItemTemplate>
Salu2
__________________
Nadie roba nada ya que en la vida todo se paga . . .

Exentrit - Soluciones SharePoint & Net
  #3 (permalink)  
Antiguo 14/03/2005, 16:13
Avatar de Sayra  
Fecha de Ingreso: diciembre-2004
Mensajes: 365
Antigüedad: 19 años, 5 meses
Puntos: 1
oye muchas gracias,
Nos vemos
  #4 (permalink)  
Antiguo 14/03/2005, 17:08
Avatar de Sayra  
Fecha de Ingreso: diciembre-2004
Mensajes: 365
Antigüedad: 19 años, 5 meses
Puntos: 1
Hola de nuevo veras de la misma forma que me explicaste agregue dos combos mas (en total tengo 3)

Pero tengo una duda

Se supone que debo enlazar el drops 2 (Ciudad)con el drop1 (Estado) de manera que solo cargue las ciudades correspondientes al Estado

Yo hice ese enlace una vez, a traves del evento onselectionchange del drop1 carga al drop2

Pero para este caso que tengo los drop dentro del grid ¿Que es lo mas recomendable?

Ahh otra cosa
Cuando lo selecciono como hago para que quede selecionado
el valorpor ejemplo si dentro del grid depliego el combo estado y selecciono el estado4 como hagao para que quede selccecionado el estado 4

¿Entiendes?

Y una vez mas gracias por la asistencia
  #5 (permalink)  
Antiguo 15/03/2005, 07:06
Avatar de Sayra  
Fecha de Ingreso: diciembre-2004
Mensajes: 365
Antigüedad: 19 años, 5 meses
Puntos: 1
Hola bueno intente arreglar el problema asi
parq que en modo edicion tome la selccion de los combos y la guarde

lo hice asi
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("DropDownList1")
MyCommand.Parameters("@Estado").Value = StateDropDownList.SelectedItem.ToString()

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

Dim UbiDropDownList As DropDownList
UbiDropDownList = E.Item.FindControl("DropDownList3")
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

Guiando por supuesto del manual
pero sabes estoy completamente segura que lo hice mal, la embarre

me da este error,

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 117: Dim ColValue As String = CurrentTextBox.Text


y no entiendo porque esta mal
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 07:13.