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

Repeater inside repeater in GridTemplateColumn not finding DataSource

10 Answers 635 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Diane
Top achievements
Rank 1
Diane asked on 02 Oct 2008, 10:41 AM
EDIT - title is misleading - sorry - there is just a single repeater in the template column.

Hi,

I have a repeater inside a GridTemplateColumn with the datasourceid set declaratively.

<telerik:GridTemplateColumn UniqueName="tcRoles">
         <ItemTemplate>
         <ul>
            <asp:Repeater ID="rpRoles" runat="server" DataSourceID="ods_UsersInRoles">
            <ItemTemplate><li>
                <asp:Label ID="lblRoleName" runat="server" Text='<%#Eval("role_name") %>' /> (<asp:Label ID="lblApplicationName" runat="server" Text='<%#Eval("application_name") %>'/>)</li>
            </ItemTemplate>
            </asp:Repeater>
            </ul>
            <asp:ObjectDataSource ID="ods_UsersInRoles" runat="server"
        SelectMethod="GetByUserID"
        TypeName="mhs.bll.UsersInRoles">
        <SelectParameters>
            <asp:Parameter Name="user_ID" Type="Int32" />
        </SelectParameters>
    </asp:ObjectDataSource>   
        </ItemTemplate>
        </telerik:GridTemplateColumn>

I am getting an error that the repeater cannot find the datasource:

The DataSourceID of 'rpRoles' must be the ID of a control of type IDataSource.  A control with ID 'ods_UsersInRoles' could not be found.

This logic works using standard GridView - is there something I am missing when using RadGrid?

I am setting the user_ID parameter in code behind on the RadGrid ItemDataBound event.

Thanks
Tom

10 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 06 Oct 2008, 09:31 AM
Hello TomL,

To eliminate the issue, please move the datasource for the repeater outside of the grid- in this way it will be visible to the repeater.
I hope this suggestion helps.

Regards,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Bridge24
Top achievements
Rank 1
Iron
answered on 03 Feb 2009, 07:49 PM
I have this exact same issue.  and I can't put my datasource outside the template, because I use a controlparamameter to pass in parameter to my stored procedure, this controls is inside the template.

I was also able to do this with the MS datagrid.  I simply copy my template from MS to Telerik datagrid columntemplate, it is supposed to work the same way.

My "master" datasource is outside the telerik radgrid, but every item must get its sqldatasource inside each template.

dsproduct is used to load the radgrid.
dscategory is used to load a repeater inside each row of the datagrid.

This exact same code works inside an <asp:datagrid>

Do you have an alternative solution to do the same action without VB code with the radgrid?

aspx source:


<telerik:RadGrid runat="server" ID="RadGrid1" DataSourceID="dsproduct">
...
<telerik:GridTemplateColumn HeaderText="Categories">
<itemtemplate>
    <asp:Literal ID="litproductid" runat="server" Visible="false" Text='<%# Eval("product_id") %>' />
    <asp:Repeater runat="server" ID="rptcateg" DataSourceID="dscategory">
    ...
    </asp:Repeater>
    <asp:SqlDataSource ID="dscategory" runat="server" SelectCommand="spu_category_getbyproduct" ConnectionString="..."
    SelectCommandType="StoredProcedure">
        <SelectParameters>
            <asp:ControlParameter Name="product_id" Type="Int32" ControlID="litproductid" PropertyName="Text" />
        </SelectParameters>
    </asp:SqlDataSource>
</itemtemplate>
</telerik:GridTemplateColumn>
...
</telerik:RadGrid>
< asp:SqlDataSource ID="dsproduct" runat="server" ConnectionString="..." SelectCommand="spu_Product_getbyclient" SelectCommandType="StoredProcedure">
<selectparameters>
        <asp:Parameter Name="client_id" Type="Int32" />
    </selectparameters>
</asp:SqlDataSource>
0
Bridge24
Top achievements
Rank 1
Iron
answered on 03 Feb 2009, 08:22 PM
I did some other tests and it really works in <ASP:Datagrid> and NOT in <telerik:radgrid>.

I copy the exact same template, that should work in both grids.

<itemtemplate>
<asp:Literal ID="litproductid" runat="server" Visible="false" Text='<%# Eval("product_id") %>' />
<asp:Repeater runat="server" ID="rptcateg" DataSourceID="dscategory">
<asp:Label ID="lblcat" runat="server" Text='<%# Eval("name") %>'></asp:Label>
</asp:Repeater>
<asp:SqlDataSource ID="dscategory" runat="server" SelectCommand="spu_category_getbyproduct"  ConnectionString="..." SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter Name="product_id" Type="Int32" ControlID="litproductid" PropertyName="Text" />
</SelectParameters>
</asp:SqlDataSource>
</itemtemplate>
0
Yavor
Telerik team
answered on 06 Feb 2009, 02:43 PM
Hello Dani,

This is the case because the template column is a naming container of its own.
Attached to this message, is a screenshot, demonstrating the resulting uniqueId for the datasource control, nested in a template like this:

.aspx
 <telerik:GridTemplateColumn UniqueName="Template1">  
                        <ItemTemplate> 
                             <asp:Literal ID="litproductid" runat="server" Visible="false" Text='<%# Eval("CustomerID") %>' /> 
                            <asp:Repeater runat="server" ID="rptcateg" > 
                            <ItemTemplate>                              
                                <asp:Label ID="lblcat" runat="server" Text='<%# Eval("CustomerID") %>'></asp:Label> 
                                </ItemTemplate> 
                            </asp:Repeater> 
                            <asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="~/App_Data/Nwind.mdb" 
                                SelectCommand="SELECT TOP 10 [OrderID], [CustomerID], [EmployeeID], [Freight] FROM [Orders]">  
                            </asp:AccessDataSource> 
                        </ItemTemplate> 
                    </telerik:GridTemplateColumn> 

Kind regards,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Bridge24
Top achievements
Rank 1
Iron
answered on 09 Feb 2009, 03:06 PM
I finally did it in codebehind...
dgproducts_ItemDataBound 
...
rpt = DirectCast(e.Item.FindControl("rptcateg"), Repeater) 
ds = DirectCast(e.Item.FindControl("dscategory"), SqlDataSource) 
rpt.DataSource = ds 
rpt.DataBind() 


But it's strange that this exact same action can be done by using the DataSourceID property of the reapeater/sqldatasource when I use it inside a ASP:Datagrid or ASP:Repeater itemtemplate, but it doesn't work with the telerik:grid, I must some codebehind to databind it.



0
Yavor
Telerik team
answered on 10 Feb 2009, 06:55 AM
Hi Dani,

I am glad that the setup is working at your end now.
As mentioned previously, the two controls are slightly different in this aspect, and because the datasource is in a separate naming container, it cannot be located.

Kind regards,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Francis Frank
Top achievements
Rank 1
answered on 31 Aug 2010, 12:21 PM
Please i think it will benefit us more if the Telerik team can do something about this issue rather than for  the programmers to keep believing this is impossible whereas alot of implementation tasks require it
At least there should be a parent-child relationship exising among the controls despite the container differences

Thanks, Team
0
Tsvetoslav
Telerik team
answered on 01 Sep 2010, 03:37 PM
Hello Francis,

The GridTemplateColumn does support the requirement you are targeting at, however, it is necessary that the DataSource control be placed before the Repeater one in the ItemTemplate mark-up. The reason for this is that if the Repeater is declared before the data-source controls, the grid will add the Repeater first to the template container of the column. This will call the Repeater's Load method which for it part will try to data-bind the control. At this point, however, the data-source controls has still not been added to the page and binding the Repeater will fail.

Hope it helps.

Regards,
Tsvetoslav
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
Francis Frank
Top achievements
Rank 1
answered on 03 Sep 2010, 07:36 AM
Thanks for the reply Tsvetoslav How can one declare the Datasource control before the Repeater as u were illustrating?
The below code helped me BUT it I had to bypass the major thing i wanted to achieve.
The below code is placed inside an ItemDataBound and it gave me the RadListViewItemEventArgs "e" but i need a way to triger the same even on button or label click not on ItemDataBound

// RadListView ItemDataBound     
 if (e.Item is RadListViewDataItem)
            {
                RadListViewDataItem item = e.Item as RadListViewDataItem;
                RadRotator rotator = item.FindControl("RadRotator1") as RadRotator;
 
                rotator.Visible = false;
                string cId = item.GetDataKeyValue("ClientId").ToString();
 
                //check whether the client subscribed for Advert
                    if (Accounts.checkAdvertPlacement(cId) == true)
                    {
                        SqlDataSource2.SelectParameters[0].DefaultValue = cId;
                        rotator.DataSource =    SqlDataSource2.Select(DataSourceSelectArguments.Empty);
                        rotator.DataBind();
 
                        ConfigureRotator(rotator);
                        rotator.Visible = true;
                    }
            }
Thanks
Tsvetoslav
0
Tsvetoslav
Telerik team
answered on 03 Sep 2010, 12:36 PM
Hello Francis,

I am attaching a small sample. It is by far not a real-world example but is enough to demonstrate my point.

Hope it will prove useful.

Regards,
Tsvetoslav
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
Diane
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Bridge24
Top achievements
Rank 1
Iron
Francis Frank
Top achievements
Rank 1
Tsvetoslav
Telerik team
Share this question
or