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
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"
));
}
}
}
}
}