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

creating dynamic columns containing rad comboboxes in rad grid

1 Answer 48 Views
Grid
This is a migrated thread and some comments may be shown as answers.
anirud
Top achievements
Rank 1
anirud asked on 10 Mar 2011, 02:22 PM
on the index change of rad combobox arad grid must appear with dynamically created columns containing rad comboboxes and those comboboxes are to be binded with some data from database.the columns with comboboxes are coming but i am unable to bind with data. i am doing this programmatically using ITEMPLATE interface by inheriting in a class and calling InstantiateIn method.
help by sending or posting a code snippet.
thanks in advance
Anirud
    //calling this function inside an event
    public void loadGrid()
    {
      //looping for creating 31 columns
            for (int I_ColumnCount = 1; I_ColumnCount <= 31; I_ColumnCount++)
            {
                 
                GridTemplateColumn gridtemplatecolumn = new GridTemplateColumn();
                gridtemplatecolumn.ItemTemplate = new MyTemplate(Convert.ToString(I_ColumnCount));
                gridtemplatecolumn.HeaderText = Convert.ToString(I_ColumnCount);
                this.rg_Attendence.MasterTableView.Columns.Add(gridtemplatecolumn);
                ViewState["grid_DayCount"]=Convert.ToString(I_ColumnCount);
            }
    }
    
    public class MyTemplate : ITemplate
    {
        protected RadComboBox lblControl;
        public string colname;
        public MyTemplate(string cName)
        {
            colname = cName;
             
        }
        public void InstantiateIn(System.Web.UI.Control container)
        {
             
            lblControl = new RadComboBox();
            lblControl.ID = colname;
            container.Controls.Add(lblControl);
        }
    }
 
    //this function contains data which is retrieved from database and need to bind to rad grid and comboboxes(which are created inside rad grid dynamically)
    protected void loadEmployees()
    {
            RadComboBox lblControl = new RadComboBox();
            
            DataTable DT_Employee = new DataTable();
            DT_Employee = BLL.get_Attendance(_obj_Smhr_Attendance);
            if (DT_Employee.Rows.Count == 0)
            {
                
                    rg_Attendence.Visible = true;
                    rg_Attendence.DataSource = DT_Employee;
                    rg_Attendence.DataBind();
                    for (i = 0; i <= rg_Attendence.Items.Count - 1; i++)
                    {
                        //here i am trying to bind data to comboboxes which are created dynamically inside rad grid
                        rcmbList = rg_Attendence.Items[i].FindControl("lblControl") as RadComboBox;
                        if (Convert.ToString(Convert.ToString(DT_Employee.Rows[i][3])) == "0")
                            rcmbList.SelectedIndex = rcmbList.FindItemIndexByValue(Convert.ToString("P"));
                        else if (Convert.ToString(Convert.ToString(DT_Employee.Rows[i][3])) == "1")
                            rcmbList.SelectedIndex = rcmbList.FindItemIndexByValue(Convert.ToString("L"));
                        
                    }
                }
                else
                {
                    rg_Attendence.Visible = false;
                    btn_Save.Visible = false;
                    btn_Finalize.Visible = false;
                }
            }
            else
            {
                _obj_Smhr_Attendance.OPERATION = operation.Check;
                _obj_Smhr_Attendance.ATTENDANCE_MODE = true;
                DT_Employee = BLL.get_Attendance(_obj_Smhr_Attendance);
                rg_Attendence.Visible = true;
                rg_Attendence.DataSource = DT_Employee;
                rg_Attendence.DataBind();
                for (i = 0; i <= rg_Attendence.Items.Count - 1; i++)
                {
                    //here i am trying to bind data to comboboxes which are created dynamically inside rad grid 
                    lblControl = rg_Attendence.Items[i].FindControl("colname") as RadComboBox;
                    if ((Convert.ToString(Convert.ToString(DT_Employee.Rows[i][2]))).Trim() == "P")
                    {
                        lblControl.SelectedIndex = lblControl.FindItemIndexByValue(Convert.ToString("P"));
                    }
                    else if ((Convert.ToString(Convert.ToString(DT_Employee.Rows[i][2]))).Trim() == "L")
                    {
                        lblControl.SelectedIndex = lblControl.FindItemIndexByValue(Convert.ToString("L"));
                    }
                    
                     
                }
                
            }
            
    }
}

1 Answer, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 15 Mar 2011, 04:46 PM
Hello anirud,

Please see the answer provided in the other thread you have posted on the same subject.

Greetings,
Iana
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
Grid
Asked by
anirud
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Share this question
or