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

[Solved] GridTemplateColumn

1 Answer 97 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ayesha
Top achievements
Rank 1
Ayesha asked on 03 Aug 2009, 01:42 AM

Hi,

1) I need a column in radgrid with a dropdownlist with runtimebinding of the values.
2) The column should always be in  the dropdownlist with the values.
3) The grid should not have edit command column.
4) Selected value of the dropdown should be from datasource of radgrid.

But my datasource is a list<class> . so, how do i set the datasourceid and datatext and datavalue  if it is a list<class>.
Pls do elp me with code.


I'm doing the foll:
in ascx,GridTemplateColumn

 

<telerik:GridTemplateColumn HeaderText="mycol" UniqueName ="temp1">

 

 

<ItemTemplate>

 

 

<asp:DropDownList ID="ddl" runat="server"></asp:DropDownList>

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 


in ascx.cs:

in grid's itemdatabound event , i do this

if

 

(e.Item is GridDataItem)

 

{

 

GridDataItem item = (GridDataItem)e.Item;

 

 

DropDownList ddl1 = (DropDownList)item["temp1"].FindControl("ddl");

 

ddl1.DataSourceID = ?

ddl1.DataTextField =?


ddl1.DataValueField =?
ddl1.DataBind();

 

}


I don't know what to fill in the ? with. pls help me with code.


1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 03 Aug 2009, 05:12 AM
Hello Zaheka,

I am not sure of what your class contains but in your case, to bind your dropdownlist to a list you have to make use of the DataSource property of the dropdownlist control rather than using the DataSourceId property which points to a DataSource control. Here's an example on how to bind the dropdownlist to a list:
c#:
 protected void LoadList()  
    { 
        List<myClass> myCList = new List<myClass>();   
  
        myClass c1 = new myClass();  
        c1.ID = 1;  
        c1.Name = "Bob";  
        c1.Color = "Blue";  
  
        myCList.Add(p1);                
  
    }  

protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
       if(e.Item is GridDataItem) 
        { 
           GridDataItem item = (GridDataItem)e.Item; 
           DropDownList ddl1 = (DropDownList)item["temp1"].FindControl("ddl"); 
           ddl1.DataSource = myCList; 
           ddl1.DataTextField = "Color"
           ddl1.DataValueField = "ID"
           ddl1.DataBind(); 
        } 
    } 
 

Thanks
Princy.
Tags
Grid
Asked by
Ayesha
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or