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

Update RadGrid inside Repeater

1 Answer 221 Views
Grid
This is a migrated thread and some comments may be shown as answers.
archimede
Top achievements
Rank 1
archimede asked on 07 Jul 2010, 11:28 AM

I have a web page that shows a parameters grid for each parameter group.
To achieve this result I want to use an asp Repeater. I can see the grid correctly but the radGrid update seems not to work. I think the grid cannot find the datasource at the update event.

This is the part on my page:

<table width="100%;">  
        <tr> 
            <td> 
                <div style="width: 7cm;">  
                </div> 
            </td> 
            <td style="text-align: right;">  
            <asp:Label ID="LabelGruppo" runat="server" Text="Label"></asp:Label> 
                <telerik:RadComboBox ID="RadComboBoxGruppo" runat="server" DataSourceID="ObjectDataSourceGruppiParametriComboBox" 
                    DataTextField="NomeGruppo" DataValueField="IdGruppo" AutoPostBack="True" 
                    AppendDataBoundItems="True">  
                    <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" 
        OnItemDataBound="ParentRepeater_ItemDataBound">  
        <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">  
                <ClientSettings> 
                    <Selecting EnableDragToSelectRows="False" AllowRowSelect="True" /> 
                </ClientSettings> 
                <MasterTableView AutoGenerateColumns="False">  
                    <RowIndicatorColumn> 
                        <HeaderStyle Width="20px"></HeaderStyle> 
                    </RowIndicatorColumn> 
                    <ExpandCollapseColumn> 
                        <HeaderStyle Width="20px"></HeaderStyle> 
                    </ExpandCollapseColumn> 
                    <Columns> 
                        <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" Visible="false">  
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="IdCultura" DataType="System.Int64" HeaderText="IdCultura" 
                            SortExpression="IdCultura" UniqueName="IdCultura" Visible="false">  
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="DescrizioneParametro" HeaderText="DescrizioneParametro" 
                            SortExpression="DescrizioneParametro" UniqueName="DescrizioneParametro">  
                        </telerik:GridBoundColumn> 
                    </Columns> 
                    <EditFormSettings> 
                        <EditColumn> 
                        </EditColumn> 
                    </EditFormSettings> 
                </MasterTableView> 
            </telerik:RadGrid> 
            <asp:ObjectDataSource ID="ObjectDataSourceParametri" runat="server" SelectMethod="getAll" 
        TypeName="MachinaWeb.Services.BO_ConfigurazioneProgramma_Parametro">  
        <SelectParameters> 
            <asp:Parameter Name="_idGruppoParametro" Type="Int64" /> 
            <asp:ControlParameter ControlID="HiddenFieldIdCultura" Name="_idCultura" PropertyName="Value" 
                Type="Int64" /> 
        </SelectParameters> 
    </asp:ObjectDataSource> 
            <asp:HiddenField ID="HiddenFieldIdGruppo" runat="server" Value='<%# DataBinder.Eval(Container.DataItem,"IdGruppo")%>' /> 
        </ItemTemplate> 
        <SeparatorTemplate> 
            <%----- fine gruppo -----%> 
            <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> 
    <asp:HiddenField ID="HiddenFieldIdCultura" runat="server" /> 

And this is code:
protected void Page_Load(object sender, EventArgs e)  
    {  
        HiddenFieldIdCultura.Value = ((SessionInformation)Session["sessionData"]).IdCultura.ToString();  
 
        BO_Azienda bo_azienda = new BO_Azienda(((SessionInformation)Session["sessionData"]).IdAzienda);  
        LabelNomeAzienda.Text = bo_azienda.NomeAzienda;  
        LabelIntestazioneAzienda.Text = bo_azienda.Intestazione;  
    }  
 
    protected void ParentRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)  
    {  
        if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))  
        {  
 
            RadGrid radGrid = (RadGrid)e.Item.FindControl("RadGridParametriConfigurazione");  
            ObjectDataSource ObjectDataSourceParametri = (ObjectDataSource)e.Item.FindControl("ObjectDataSourceParametri");  
            ObjectDataSourceParametri.SelectParameters["_idGruppoParametro"].DefaultValue = ((HiddenField)e.Item.FindControl("HiddenFieldIdGruppo")).Value;  
 
            radGrid.DataSource = ObjectDataSourceParametri;  
            radGrid.DataBind();  
        }  
    } 

1 Answer, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 09 Jul 2010, 04:05 PM
Hi archimede,

In order to enable automatic operation with RadGrid, set the AllowAutometicUpdates/AllowAutomaticDeletes/AllowAutomaticInserts properties to true. Also make sure the data source control is configured so it supports Insert, Update and Delete operations.

Additionally, I suggest that you modify your server side code as below:

protected void Page_Load(object sender, EventArgs e)   
    {   
        HiddenFieldIdCultura.Value = ((SessionInformation)Session["sessionData"]).IdCultura.ToString();   
    
        BO_Azienda bo_azienda = new BO_Azienda(((SessionInformation)Session["sessionData"]).IdAzienda);   
        LabelNomeAzienda.Text = bo_azienda.NomeAzienda;   
        LabelIntestazioneAzienda.Text = bo_azienda.Intestazione;   
    }   
    
    protected void ParentRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)   
    {   
        if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))   
        {   
    
            RadGrid radGrid = (RadGrid)e.Item.FindControl("RadGridParametriConfigurazione");   
            ObjectDataSource ObjectDataSourceParametri = (ObjectDataSource)e.Item.FindControl("ObjectDataSourceParametri");   
            ObjectDataSourceParametri.SelectParameters["_idGruppoParametro"].DefaultValue = ((HiddenField)e.Item.FindControl("HiddenFieldIdGruppo")).Value;   
    
            radGrid.DataBind();   
        }   
    }  

And for a sample on how to achieve automatic data source operations with ObjectDataSource control, you can try out this code library.

Kind regards,
Iana
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
Tags
Grid
Asked by
archimede
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Share this question
or