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

Grid Template Column

1 Answer 38 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jianan
Top achievements
Rank 1
Jianan asked on 06 Nov 2013, 06:40 PM
I have a datafield called type and it store the value of what kind of control it will use. For example, if the value is dropdownlist, I will create a dropdownlist for the user. And I am going to create a column that will create different control according to the value. If the value of current row is textbox, then this row is a textbox. Do you guys have any suggestion on how to implement it? I am thinking of template column, but I have no idea how to create the template column according to specific row.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 07 Nov 2013, 07:23 AM
Hi Jianan,

Please try the sample code snippet, i have tried a similar scenario.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem data = (GridDataItem)e.Item;
        string id = data["Control"].Text; //To identify the rows for controls
        data["type"].Text = string.Empty;
        switch (id)
        {
            case "RadComboBox":                   
                RadComboBox combo = new RadComboBox();
                combo.DataSourceID = "SqlDataSource2";
                combo.DataTextField = "Values";
                combo.DataValueField = "Values";
                combo.ID = "Radcombobox1";
                data["type"].Controls.Add(combo);
                break;
 
            case "TextBox":
                TextBox txtbox = new TextBox();                  
                txtbox.ID = "TextBox1";
                data["type"].Controls.Add(txtbox);
                break;    
            
             //Similar Cases for your required controls          
        }           
    }
}

Thanks,
Shinu
Tags
Grid
Asked by
Jianan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or