Ver Mensaje Individual
  #1 (permalink)  
Antiguo 14/11/2006, 05:32
Motki
 
Fecha de Ingreso: septiembre-2003
Mensajes: 341
Antigüedad: 21 años, 6 meses
Puntos: 0
Selectitem en dropdown de DataGrid Editable

Hola a todos.
Tengo un datagrid que es editable.Cuando lo edito tengo un dropdownlist que relleno de una base de datos.
Estoy intentando seleccionar el elemento dentro del dropdonwlist pero no lo consigo.
El error que me aparece es el siguiente:
Object reference not set to an instance of an object.
Este es mi código:
Lo que intento es en el proceso de edición que se seleccione el item que quiero (dgProducts_Edit):



Sub BindData()
Dim objConnection As OleDbConnection
Dim objCommand As OleDbCommand
Dim strSQLQuery As String
Dim conexiondb as string
conexiondb = ConfigurationSettings.AppSettings("strConnect")
objConnection = New OleDbConnection(conexiondb)
Dim i as integer
strSQLQuery = " select SubMenu.idSubMenu, Submenu.NombreSubmenu, SubMenu.descripSubMenu, SubMenu.Orden, SubMenu.Link, SubMenu.Target, " & _
" Submenu.orden " & _
" from submenu inner join Relacion_MenuSubmenu on submenu.idSubMEnu = Relacion_MenuSubmenu.idSubMenu " & _
" where Relacion_MenuSubMenu.idMenu ="&idM
objCommand = New OleDbCommand(strSQLQuery, objConnection)
objConnection.Open()
Dim objDR as OleDbDataReader
objDR = objCommand.ExecuteReader()
dgProducts.DataSource = objDR
dgProducts.DataBind()
objConnection.close()
End Sub


Sub dgProducts_Edit(sender As Object, e As DataGridCommandEventArgs)
dgProducts.EditItemIndex = e.Item.ItemIndex
BindData()
Dim strLabTarget as String = CType(e.item.FindControl("LabTarget"),Label).Text
Dim strTargettmp as DropDownList = CType(e.Item.FindControl("Target"), DropDownList)
strTargettmp.Items.FindByValue(strLabTarget).selec ted = true
End Sub


// funcion que rellena el dropdonw list Target
Function GetTipoTarget()
Dim objConnection As OleDbConnection
Dim objCommand As OleDbCommand
Dim strSQLQuery As String
Dim conexiondb as string
conexiondb = ConfigurationSettings.AppSettings("strConnect")
objConnection = New OleDbConnection(conexiondb)
strSQLQuery = "select target from Target"
objCommand = New OleDbCommand(strSQLQuery, objConnection)
objConnection.Open()
'3. Create/Populate the DataReader
Dim objDR2 as OleDbDataReader
objDR2 = objCommand.ExecuteReader()
return objDR2
objConnection.close()
end function
Este es el datagrid:

<asp:DataGrid id="dgProducts" runat="server" AutoGenerateColumns="False" CellPadding="4"
OnItemCommand="dgProducts_Add" OnEditCommand="dgProducts_Edit" OnUpdateCommand="dgProducts_Update" OnCancelCommand="dgProducts_Cancel"
OnDeleteCommand="dgProducts_Delete" showFooter="True" PageSize="5" DataKeyField="idSubmenu">
<asp:TemplateColumn HeaderText="Target" FooterText="&lt;input type='text' class='inputitems' size='10' name='strTarget'&gt;">
<ItemTemplate>
<asp:Label id="LabTarget" text='<%# DataBinder.Eval(Container.DataItem, "Target")%>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<ItemStyle verticalaling="top" horizontalalign="Left" cssclass="inputitems"></ItemStyle>
<asp:DropDownList id="Target" DataTextField="Target" DataTextValue="Target" DataSource="<%# GetTipoTarget() %>" class="inputitems" runat="server" />
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList runat="server" id="AddtipoTarget" DataValueField="Target" DataTextField="Target" DataSource='<%# GetTipoTarget() %>' class="inputitems" />
</FooterTemplate>
</asp:TemplateColumn>


</asp:DataGrid>
__________________
---Nuestra recompensa se encuentra en el esfuerzo y no en el resultado. Un esfuerzo total es una victoria completa.-- GHANDI