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

How to use a Grid in EditItemTemplate

3 Answers 56 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
Anto (DLL Version : 2008.3.1314.35) asked on 05 Jan 2010, 10:48 AM
Hi All

Have a grid with some datas from a table M_Products (ProductID, Name, ItemID).

While Edit or Add New Record is clicked, Need to show another grid with datas from M_Item table (ItemID, Item Name).

This is due to, Have to display all the items with (M_Product.ItemID=M_Item.ItemID).

So have to show another grid inside EditItemTemplate.

Please could I know is there any possible way.

Thank You.

-Anto




3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 05 Jan 2010, 12:22 PM
Hi Anto,

Here's an example for the required scenario. Try it out:
aspx:
<telerik:RadGrid ID="RadGrid1" AutoGenerateColumns="false" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource1">                 
      <MasterTableView CommandItemDisplay="Top" DataKeyNames="ID">     
            <Columns> 
                <telerik:GridTemplateColumn UniqueName="TemplateColumn">                 
                <EditItemTemplate> 
                <telerik:RadGrid ID="RadGrid2"  runat="server" OnNeedDataSource="RadGrid2_NeedDataSource"></telerik:RadGrid> 
                </EditItemTemplate> 
                </telerik:GridTemplateColumn> 
                 .....  

c#:
 protected void RadGrid2_NeedDataSource(object source, GridNeedDataSourceEventArgs e) 
    { 
        RadGrid grid = (RadGrid)source; 
        string ID = ((GridEditFormItem)grid.NamingContainer).ParentItem.GetDataKeyValue("ID").ToString();          
        //use this(M_Product.ItemID = ID) in the where clause of the Sql Select query and populate the grid  
 
    } 

Princy.
0
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
answered on 05 Jan 2010, 12:59 PM
Hi Princy,

Please could I know how to bind the RadGrid2.

I tired, but i got a error "RadGrid2 does not exists in the current context

Thank You

-Anto
0
Princy
Top achievements
Rank 2
answered on 06 Jan 2010, 08:23 AM
Hello Anto,

You can populate the grid nested inside the main grid using the following code:
c#:
protected void RadGrid2_NeedDataSource(object source, GridNeedDataSourceEventArgs e)  
    {  
        RadGrid grid = (RadGrid)source;  
        string ID = ((GridEditFormItem)grid.NamingContainer).ParentItem.GetDataKeyValue("Age").ToString();   
        grid.DataSource = GetDataTable("SELECT ItemID, Item Name FROM M_Item WHERE M_Item.ItemID ='" + ID + "'");  
 
         //GetDataTable() is the method which contains the connection strings to execute the select query 
    }  

Hope this helps..
Princy.
Tags
Grid
Asked by
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
Share this question
or