This is a migrated thread and some comments may be shown as answers.

Repeater, Grid and dynamically loaded RadComboBox

2 Answers 411 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
archimede
Top achievements
Rank 1
archimede asked on 09 Jul 2010, 04:57 PM
The situation is quite complex.
I have a repeater that show multiple groups of parameters in a grid. So in each repeater item I have a radGrid with the relative parameters.
A user can go in edit mode in the grid and he'll see a dinamically created combobox. In database I have a SQL query string for each parameter to load a different set of data in combobox. To achieve this I've done this:

- in edittemplate I put the combobox and a hiddenfield bound to database query string (used to load values in combobox)
- outside repeater I've another hiddenfield used by combobox (placed in repeater edit item) datasource

The idea is that when a user click and goes into edit for one row the hiddenfield's grid value (that inside repeater), the value is repeated into the hiddenfield external to the repeater. So the combobox will be correctly loaded as we want.

I have to mantain syncronized the two hiddenfield (inside and outside repeater). The problem is I have to use the ItemCommand Event (Edit Command) and cannot attach to the item databound event that comes after the combobox load. How can I find the value of hiddenfield inside repeater at itemcommand?

There are other smarter solution? I've tryed to place the combobox's datasource inside repeater edittemplate but received an error.

I post here an image of the web application and the page aspx and source code for details:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Telerik.Web.UI;
using MachinaWeb.Services;
using MachinaWeb.CommonClasses;
  
public partial class Configuration_Companies : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        HiddenFieldIdCultura.Value = ((SessionInformation)Session["sessionData"]).IdCultura.ToString();
        HiddenFieldIdAzienda.Value = ((SessionInformation)Session["sessionData"]).IdAzienda.ToString();
  
        BO_Azienda bo_azienda = new BO_Azienda(((SessionInformation)Session["sessionData"]).IdAzienda);
        LabelNomeAzienda.Text = bo_azienda.NomeAzienda;
        LabelIntestazioneAzienda.Text = bo_azienda.Intestazione;
    }
  
    protected void Repeater1_PreRender(object sender, EventArgs e)
    {
        foreach (RepeaterItem item in Repeater1.Items)
        {
            //Dinamically generate DataSource and associate it to Repeater Item
            ObjectDataSource ods = new ObjectDataSource();
            ods.TypeName = "MachinaWeb.Services.BO_ConfigurazioneProgramma_Parametro";
            ods.SelectMethod = "getAll";
            ods.UpdateMethod = "updateParametro";
            ods.SelectParameters.Add("_idCultura", DbType.Int64, HiddenFieldIdCultura.Value);
            ods.SelectParameters.Add("_idAzienda", DbType.Int64, HiddenFieldIdAzienda.Value);
            ods.SelectParameters.Add("_idGruppoParametro", DbType.Int64, ((HiddenField)item.FindControl("HiddenFieldIdGruppo")).Value);
  
            RadGrid radGrid = (RadGrid)item.FindControl("RadGridParametriConfigurazione");
            radGrid.DataSource = ods;
            radGrid.DataBind();
        }
    }
  
    protected void RadGridParametriConfigurazione_UpdateCommand(object sender, GridCommandEventArgs e)
    {
        ObjectDataSourceForUpdate.SelectParameters["_idCultura"].DefaultValue = HiddenFieldIdCultura.Value;
        ObjectDataSourceForUpdate.SelectParameters["_idAzienda"].DefaultValue = HiddenFieldIdAzienda.Value;
        ObjectDataSourceForUpdate.SelectParameters["_idGruppoParametro"].DefaultValue = ((Label)e.Item.FindControl("LabelTipoParametro")).Text;
  
        ((RadGrid)sender).DataSource = ObjectDataSourceForUpdate;
    }
  
    protected void RadGridParametriConfigurazione_ItemDataBound(object source, GridItemEventArgs e)
    {
        if (!(e.Item is GridDataInsertItem) && e.Item.IsInEditMode)
        //item is about to be edit  
        {
            long tipoParametro = long.Parse(((HiddenField)e.Item.FindControl("HiddenFieldTipoControllo")).Value);
            //HiddenFieldQuery.Value = ((HiddenField)e.Item.FindControl("HiddenFieldQueryRiga")).Value;
  
            try
            {
                switch (tipoParametro)
                {
                    case 1:
                        //CheckBox
                        ((RadComboBox)e.Item.FindControl("RadComboBoxValore")).Visible = false;
                        ((TextBox)e.Item.FindControl("TextBoxDescrizione")).Visible = false;
                        ((CheckBox)e.Item.FindControl("CheckBoxAbilitatoE")).Visible = true;
                        break;
                    case 2:
                        //CheckBox-ComboBox
                        ((RadComboBox)e.Item.FindControl("RadComboBoxValore")).Visible = true;
                        ((TextBox)e.Item.FindControl("TextBoxDescrizione")).Visible = false;
                        ((CheckBox)e.Item.FindControl("CheckBoxAbilitatoE")).Visible = true;
                        break;
                    case 3:
                        //TextBox
                        ((RadComboBox)e.Item.FindControl("RadComboBoxValore")).Visible = false;
                        ((TextBox)e.Item.FindControl("TextBoxDescrizione")).Visible = true;
                        ((CheckBox)e.Item.FindControl("CheckBoxAbilitatoE")).Visible = false;
                        break;
                    case 4:
                        //ComboBox
                        ((RadComboBox)e.Item.FindControl("RadComboBoxValore")).Visible = true;
                        ((TextBox)e.Item.FindControl("TextBoxDescrizione")).Visible = false;
                        ((CheckBox)e.Item.FindControl("CheckBoxAbilitatoE")).Visible = false;
                        break;
                    case 5:
                        //CheckBox-TextBox
                        ((RadComboBox)e.Item.FindControl("RadComboBoxValore")).Visible = false;
                        ((TextBox)e.Item.FindControl("TextBoxDescrizione")).Visible = true;
                        ((CheckBox)e.Item.FindControl("CheckBoxAbilitatoE")).Visible = true;
                        break;
                }
            }
            catch (NullReferenceException)
            {
            }
        }
    }
  
    protected void HiddenFieldQueryRiga_ValueChanged(object sender, EventArgs e)
    {
  
    }
}

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
    CodeFile="Aziende.aspx.cs" Inherits="Configuration_Companies" %>
  
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolderBody" runat="Server">
    <asp:Label ID="LabelIntestazione" runat="server" Text="LabelIntestazione" Font-Names="Arial"
        Font-Size="13px" Font-Bold="True"></asp:Label>
    <table style="font-family: Arial; font-size: 13px; margin-top: 10px;">
        <tr>
            <td colspan="2">
                <b>
                    <asp:Label ID="LabelIntestazioniDatiAzienda" runat="server" Text="Label"></asp:Label>
                </b>
            </td>
        </tr>
        <tr>
            <td>
                <asp:Label ID="LabelNomeAziendaTxt" runat="server" Text="LabelNomeAzienda"></asp:Label>
            </td>
            <td>
                <asp:Label ID="LabelNomeAzienda" runat="server" Text="Label"></asp:Label>
            </td>
        </tr>
        <tr>
            <td>
                <asp:Label ID="LabelIntestazioneAziendaTxt" runat="server" Text="Label"></asp:Label>
            </td>
            <td>
                <asp:Label ID="LabelIntestazioneAzienda" runat="server" Text="Label"></asp:Label>
            </td>
        </tr>
    </table>
    <br />
    <table width="100%;">
        <tr>
            <td>
                <div style="width: 7cm;">
                </div>
            </td>
            <td style="text-align: right;">
                <asp:Label ID="LabelGruppo" runat="server" Text="Label" Font-Names="Arial" Font-Size="11pt"></asp:Label>
                <telerik:RadComboBox ID="RadComboBoxGruppo" runat="server" DataSourceID="ObjectDataSourceGruppiParametriComboBox"
                    DataTextField="NomeGruppo" DataValueField="IdGruppo" AutoPostBack="True" AppendDataBoundItems="True"
                    Width="300px">
                    <Items>
                        <telerik:RadComboBoxItem runat="server" Text="---" Value="-1" />
                    </Items>
                </telerik:RadComboBox>
                <asp:ObjectDataSource ID="ObjectDataSourceGruppiParametriComboBox" runat="server"
                    SelectMethod="getAll" TypeName="MachinaWeb.Services.BO_ConfigurazioneProgramma_GruppoParametri">
                    <SelectParameters>
                        <asp:ControlParameter ControlID="HiddenFieldIdCultura" Name="_idCultura" PropertyName="Value"
                            Type="Int64" />
                    </SelectParameters>
                </asp:ObjectDataSource>
            </td>
        </tr>
    </table>
    <asp:Repeater ID="Repeater1" runat="server" DataSourceID="ObjectDataSourceGruppiParametri"
        OnPreRender="Repeater1_PreRender">
        <HeaderTemplate>
        </HeaderTemplate>
        <FooterTemplate>
        </FooterTemplate>
        <ItemTemplate>
            <div id="IntestazioneGruppo" style="background-color: Orange; border: 1px solid black;
                text-align: center; margin-bottom: 11px;">
                <%# Eval("NomeGruppo") %>
            </div>
            </b>
            <telerik:RadGrid ID="RadGridParametriConfigurazione" runat="server" EnableEmbeddedSkins="False"
                GridLines="None" Skin="MachinaWeb" AllowPaging="true" PageSize="15" AllowAutomaticUpdates="True"
                EnableAjaxSkinRendering="False" OnItemDataBound="RadGridParametriConfigurazione_ItemDataBound"
                OnUpdateCommand="RadGridParametriConfigurazione_UpdateCommand">
                <MasterTableView AutoGenerateColumns="False" EditMode="InPlace" DataKeyNames="IdParametro">
                    <RowIndicatorColumn>
                        <HeaderStyle Width="20px"></HeaderStyle>
                    </RowIndicatorColumn>
                    <ExpandCollapseColumn>
                        <HeaderStyle Width="20px"></HeaderStyle>
                    </ExpandCollapseColumn>
                    <Columns>
                        <telerik:GridTemplateColumn Visible="false">
                            <EditItemTemplate>
                                <asp:Label ID="LabelTipoParametro" runat="server" Text='<%# Bind("IdTipoParametro") %>'></asp:Label>
                                <%--Used only for update datasource--%>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridEditCommandColumn ButtonType="ImageButton" CancelImageUrl="~/Images/ImagesGrid/Cancel.gif"
                            EditImageUrl="~/Images/ImagesGrid/Edit.gif" UpdateImageUrl="~/Images/ImagesGrid/Update.gif"
                            InsertImageUrl="~/Images/ImagesGrid/Update.gif" UniqueName="EditCommandColumn"
                            ItemStyle-Width="40px" />
                        <telerik:GridBoundColumn DataField="IdParametro" DataType="System.Int64" HeaderText="IdParametro"
                            SortExpression="IdParametro" UniqueName="IdParametro" ReadOnly="true" Visible="false">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="IdCultura" DataType="System.Int64" HeaderText="IdCultura"
                            SortExpression="IdCultura" UniqueName="IdCultura" ReadOnly="true" Visible="false">
                        </telerik:GridBoundColumn>
                        <telerik:GridTemplateColumn Resizable="false" ItemStyle-Width="270px">
                            <HeaderTemplate>
                                <asp:Label ID="LabelDescrizioneParametro" runat="server" Text="Parametro"></asp:Label>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:Label ID="LabelDescrizioneParametroI" runat="server" Text='<%# Bind("DescrizioneParametro") %>'
                                    Width="270px"></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:Label ID="LabelDescrizioneParametroE" runat="server" Text='<%# Bind("DescrizioneParametro") %>'
                                    Width="270px"></asp:Label>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn Resizable="false" ItemStyle-Width="270px">
                            <HeaderTemplate>
                                <asp:Label ID="LabelUnificata" runat="server" Text="Valore"></asp:Label>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:Label ID="LabelDescrizioneI" runat="server" Text='<%# Bind("ValoreTextBoxComboBox") %> '
                                    Width="270px"></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBoxDescrizione" runat="server" Text='<%# Bind("DescrizioneTextBox") %>'
                                    Width="270px"></asp:TextBox>
                                <telerik:RadComboBox ID="RadComboBoxValore" runat="server" Width="270px" DataSourceID="ObjectDataSourceRadComboBoxValore"
                                    DataTextField="Descrizione" DataValueField="Valore" SelectedValue='<%# Bind("ValoreComboBox") %>'>
                                </telerik:RadComboBox>
                                <asp:HiddenField ID="HiddenFieldQueryRiga" runat="server" Value='<%# Bind("QueryComboBox") %>' />
                                <asp:Label ID="LabelHidden1" runat="server" Text='<%# Bind("QueryComboBox") %>' />
                                <asp:HiddenField ID="HiddenFieldTipoControllo" runat="server" Value='<%# Bind("IdTipoParametro") %>' />
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn Resizable="false" ItemStyle-Width="30px">
                            <HeaderTemplate>
                                <asp:Label ID="LabelAbilitato" runat="server" Text="Abilitato"></asp:Label>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:CheckBox ID="CheckBoxAbilitatoI" runat="server" Checked='<%# Bind("Abilitato") %>'
                                    Enabled="false" Width="30px" />
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:CheckBox ID="CheckBoxAbilitatoE" runat="server" Checked='<%# Bind("Abilitato") %>'
                                    Width="30px" />
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                    </Columns>
                    <EditFormSettings>
                        <EditColumn>
                        </EditColumn>
                    </EditFormSettings>
                </MasterTableView>
            </telerik:RadGrid>
            <asp:HiddenField ID="HiddenFieldIdGruppo" runat="server" Value='<%# DataBinder.Eval(Container.DataItem,"IdGruppo")%>' />
        </ItemTemplate>
        <SeparatorTemplate>
            <div style="margin-bottom: 20px;">
            </div>
        </SeparatorTemplate>
    </asp:Repeater>
    <asp:ObjectDataSource ID="ObjectDataSourceGruppiParametri" runat="server" SelectMethod="getAll"
        TypeName="MachinaWeb.Services.BO_ConfigurazioneProgramma_GruppoParametri">
        <SelectParameters>
            <asp:ControlParameter ControlID="HiddenFieldIdCultura" Name="_idCultura" PropertyName="Value"
                Type="Int64" />
            <asp:ControlParameter ControlID="RadComboBoxGruppo" Name="_idGruppoSelezionato" PropertyName="SelectedValue"
                Type="Int64" />
        </SelectParameters>
    </asp:ObjectDataSource>
    <%--Prova combo dinamico in repeater--%>
    <asp:ObjectDataSource ID="ObjectDataSourceRadComboBoxValore" runat="server" SelectMethod="valoriComboBox"
        TypeName="MachinaWeb.Services.BO_Query">
        <SelectParameters>
            <asp:ControlParameter ControlID="HiddenFieldQuery" Name="_query" DbType="String"
                PropertyName="Value" />
            <asp:ControlParameter ControlID="HiddenFieldIdCultura" Name="_idCultura" Type="Int64"
                PropertyName="Value" />
        </SelectParameters>
    </asp:ObjectDataSource>
    <asp:HiddenField ID="HiddenFieldQuery" runat="server" />
    <%--Prova combo dinamico in repeater--%>
    <asp:ObjectDataSource ID="ObjectDataSourceForUpdate" runat="server" SelectMethod="getAll"
        TypeName="MachinaWeb.Services.BO_ConfigurazioneProgramma_Parametro" UpdateMethod="updateParametro">
        <SelectParameters>
            <asp:Parameter Name="_idGruppoParametro" Type="Int64" DefaultValue="" />
            <asp:ControlParameter ControlID="HiddenFieldIdAzienda" Name="_idAzienda" PropertyName="Value"
                Type="Int64" />
            <asp:ControlParameter ControlID="HiddenFieldIdCultura" Name="_idCultura" PropertyName="Value"
                Type="Int64" />
        </SelectParameters>
        <UpdateParameters>
            <asp:ControlParameter ControlID="HiddenFieldIdAzienda" Name="_idAzienda" PropertyName="Value"
                Type="Int64" />
            <asp:ControlParameter ControlID="HiddenFieldIdCultura" Name="_idCultura" PropertyName="Value"
                Type="Int64" />
            <asp:Parameter Name="Abilitato" Type="Boolean" />
            <asp:Parameter Name="IdTipoParametro" Type="Int64" />
            <asp:Parameter Name="DescrizioneParametro" Type="String" />
            <asp:Parameter Name="DescrizioneTextBox" Type="String" />
            <asp:Parameter Name="ValoreComboBox" Type="String" />
            <asp:Parameter Name="IdParametro" Type="Int64" />
        </UpdateParameters>
    </asp:ObjectDataSource>
    <asp:HiddenField ID="HiddenFieldIdCultura" runat="server" />
    <asp:HiddenField ID="HiddenFieldIdAzienda" runat="server" />
</asp:Content>

2 Answers, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 15 Jul 2010, 04:37 PM
Hello Archimede,

I have followed your scenario and prepared a sample project for you. You can find it attached to this message.

I hope it helps.

All the best,
Mira
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
ravi
Top achievements
Rank 1
answered on 28 Jul 2015, 10:27 AM

Hi Mira,

My situation is also same but I have to update qty in text box and I am not using sqldatasource so please u can make sample project for me

Tags
General Discussions
Asked by
archimede
Top achievements
Rank 1
Answers by
Mira
Telerik team
ravi
Top achievements
Rank 1
Share this question
or