Good morning, Before starting this post I want to state that my English is not very good. I have a doubt I'm programming an aspx page where I have a webdatagrid control which has a column of type templatedatafield. This template contains a WebDropdown control. Each row represents a product webdatagrid and the template of each row contains at webdropdown indicating the product units (kilograms, pounds, etc). So my problem is that when I view the screen in edit mode I have to load their products with these webdropdowns webdropdowns and their respective items depending on the product. At the time I was able to add rows to overcome the impasse with the code show later but when I view the page in edit mode or modification only managed to load the last webdropdown. If you do not mind would like to receive many suggestions. It should be noted that working with an object webdatagrid datasource.
aspx code:
<ig:WebDataGrid ID="wdgRegistrarRC" runat="server" Height="350px" Width="900px" DataSourceID="odsRegistrarRC" AutoGenerateColumns="False" ViewStateMode="Enabled" DataKeyFields="CodigoProducto" EnableDataViewState="True" > <Columns>
<ig:BoundDataField Key="CodigoProducto" DataFieldName="CodigoProducto" Width="8%" Header-CssClass="HeaderWebdataGrid"> <Header Text="Codigo de Producto" /> </ig:BoundDataField> <ig:BoundDataField Key="Descripcion" DataFieldName="Descripcion" Width="15%" CssClass="HeaderWebdataGrid"> <Header Text="Descripción" /> </ig:BoundDataField> <ig:BoundDataField Key="CodigoUnidadMedida" DataFieldName="CodigoUnidadMedida"> </ig:BoundDataField> <ig:TemplateDataField Key="NombreUnidadesMedida" Width="6%" Header-CssClass="HeaderWebdataGrid" > <ItemTemplate> <ig:WebDropDown runat="server" Width="50px" ID="wddUnidadMedida" ClientEvents-SelectionChanged="ActualizarCodigoUnidadMedidaSeleccionada"> </ig:WebDropDown> </ItemTemplate> <Header Text="Unidad" /> </ig:TemplateDataField> <ig:BoundDataField Key="CantidadSolicitada" DataFieldName="CantidadSolicitada" Width="8%" Header-CssClass="HeaderWebdataGrid"> <Header Text="Cantidad Solicitada" /> </ig:BoundDataField> <ig:BoundDataField Key="CantidadAprobada" DataFieldName="CantidadAprobada" Width="8%" Header-CssClass="HeaderWebdataGrid"> <Header Text="Cantidad Aprobada" /> </ig:BoundDataField> <ig:BoundDataField Key="CantidadApGerencia" DataFieldName="CantidadApGerencia" Width="8%" Header-CssClass="HeaderWebdataGrid"> <Header Text="Cant. Aprob. Gerencia" /> </ig:BoundDataField> <ig:BoundDataField Key="FechaEsperada" DataFieldName="FechaEsperada" Width="9%" CssClass="HeaderWebdataGrid"> <Header Text="Fecha" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="Estado" Key="Estado" CssClass="HeaderWebdataGrid"> <Header Text="Estado del Producto" /> </ig:BoundDataField> <ig:BoundDataField Key="Semana" DataFieldName="Semana" Width="7%" CssClass="HeaderWebdataGrid"> <Header Text="Semana" /> </ig:BoundDataField> <ig:BoundDataField Key="Sustento" DataFieldName="Sustento" Width="12%" CssClass="HeaderWebdataGrid"> <Header Text="Sustento" /> </ig:BoundDataField> <ig:BoundDataField Key="Observacion" DataFieldName="Observacion" Width="12%" CssClass="HeaderWebdataGrid"> <Header Text="Observaciones" /> </ig:BoundDataField> <ig:TemplateDataField Key="Eliminar" Width="3%"> <ItemTemplate> <asp:ImageButton ID="eliminaRow" runat="server" ImageUrl="~/Images/Iconos/iconoEliminar.png" OnClientClick="EliminarProductoRequerimientoCompras();return false;" /> </ItemTemplate> </ig:TemplateDataField> </Columns> <Behaviors> <ig:EditingCore> <Behaviors> <ig:CellEditing> <CellEditingClientEvents ExitedEditMode="wdgRegistrarRC_CellEditing_ExitedEditMode" /> <EditModeActions MouseClick="Single" /> </ig:CellEditing> <ig:RowAdding Enabled="true" Alignment="Top"> <EditModeActions MouseClick="Single" EnableOnKeyPress="true" /> <ColumnSettings > <ig:RowAddingColumnSetting ColumnKey="CodigoProducto" ReadOnly="true" /> <ig:RowAddingColumnSetting ColumnKey="Descripcion" ReadOnly="true" /> </ColumnSettings> </ig:RowAdding> </Behaviors> </ig:EditingCore> <ig:RowSelectors RowNumbering="True"> </ig:RowSelectors> <ig:Selection CellClickAction="Row" RowSelectType="Single"> </ig:Selection> </Behaviors> </ig:WebDataGrid>
server code:
Protected Sub wdgRegistrarRC_InitializeRow(ByVal sender As Object, ByVal e As Infragistics.Web.UI.GridControls.RowEventArgs) Handles wdgRegistrarRC.InitializeRow Dim oListaProductosGrid = ProductoRCSL.ListarProductosPorRegistrar() Dim indexWebDropdownUnidadMedida As Integer Dim indexCodigoUnidadMedida As Integer 'For Each item In oListaProductosGrid 'For index = 0 To wdgRegistrarRC.Rows.Count - 1 ' Dim indexCodigoProducto = wdgRegistrarRC.Columns.FromKey("CodigoProducto").Index ' indexWebDropdownUnidadMedida = Me.wdgRegistrarRC.Columns.FromKey("NombreUnidadesMedida").Index ' indexCodigoUnidadMedida = Me.wdgRegistrarRC.Columns.FromKey("CodigoUnidadMedida").Index ' Dim wddUnidadMedidaCell As GridRecordItem = e.Row.Items(indexWebDropdownUnidadMedida) ' Dim wddUnidadMedida As WebDropDown = wddUnidadMedidaCell.FindControl("wddUnidadMedida") ' If (e.Row.Items(indexWebDropdownUnidadMedida).Text) Then ' Exit Sub ' Else ' Dim itemwddUnidadMedida As New DropDownItem ' e.Row.Items(indexCodigoUnidadMedida).Text = item.CodigoUnidadMedida.ToString() ' Dim oListaitemUnidadMedidaPorProducto = UnidadMedidaPorProductoSL.ObtenerUnidadesMedidaPorProducto(item) ' For Each itemUnidadMedida In oListaitemUnidadMedidaPorProducto ' Dim ddiUnidadMedida As New DropDownItem ' ddiUnidadMedida.Key = item.CodigoProducto ' ddiUnidadMedida.Text = itemUnidadMedida.AbreviaturaUnidadMedida ' ddiUnidadMedida.Value = itemUnidadMedida.CodigoUnidadMedida ' wddUnidadMedida.Items.Add(ddiUnidadMedida) ' Next ' Exit Sub ' End If 'Next ' Exit Sub 'Next If e.Row.Equals(wdgRegistrarRC.Rows(wdgRegistrarRC.Rows.Count - 1)) Then ' si es la última fila indexWebDropdownUnidadMedida = Me.wdgRegistrarRC.Columns.FromKey("NombreUnidadesMedida").Index 'columna del webdropdown indexCodigoUnidadMedida = Me.wdgRegistrarRC.Columns.FromKey("CodigoUnidadMedida").Index 'columna del codigo de unidad de medida Dim wddUnidadMedidaCell As GridRecordItem = e.Row.Items(indexWebDropdownUnidadMedida) ' el e.Row obtiene la última fila agregada ya que previamente hemos validado si es que estamos en la última fila agregada Dim wddUnidadMedida As WebDropDown = wddUnidadMedidaCell.FindControl("wddUnidadMedida") Dim oListaitemUnidadMedidaPorProducto = UnidadMedidaPorProductoSL.ObtenerUnidadesMedidaPorProducto() e.Row.Items(indexCodigoUnidadMedida).Text = oListaitemUnidadMedidaPorProducto(0).CodigoUnidadMedida.ToString() For Each item In oListaitemUnidadMedidaPorProducto Dim itemwddUnidadMedida As New DropDownItem itemwddUnidadMedida.Key = item.CodigoProducto.ToString() itemwddUnidadMedida.Text = item.AbreviaturaUnidadMedida itemwddUnidadMedida.Value = item.CodigoUnidadMedida wddUnidadMedida.Items.Add(itemwddUnidadMedida) Next oListaitemUnidadMedidaPorProducto = Nothing wdgRegistrarRC.DataBind() End If End Sub
Sorry for the code coment, thanks.
Hi abanda,
Please let me know if you need further assistance regarding this matter.
Best Regards,
Petar IvanovDeveloper Support EngineerInfragistics, Inc.http://es.infragistics.com/support
Thank you for posting in the community.
In this scenario I would suggest that you use a DropDownProvider as an editor control for one of your grid's columns instead of using a templated column. This would be more efficient as only one provider would be instantiated (as opposed to n WebDropDowns where n is the number of rows in your grid). Detailed instructions on how to setup a DropDownProvider can be found at:
http://help.infragistics.com/Help/NetAdvantage/ASPNET/2011.2/CLR4.0/html/WebDropDown_Using_WebDropDown_as_an_editor_provider_for_WebDataGrid.html
From what I understand you wish to have different items loaded in each row in the dropdown column. I would suggest that you lazy-load the items according to the row's values as illustrated at:
http://help.infragistics.com/NetAdvantage/ASPNET/2011.2/CLR4.0/
The above article is for the WebDropDown, however the principle is the same for the DropDownProvider. In your case I would suggest that you load the items in the CellEditing_EnteringEditMode client-side event.
Please let me know if this helps.