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
10 Answers, 1 is accepted
0
Hi anirud,
You can handle the ItemDataBound event for the grid to bind the combobox controls.
But if you decide to place the code for binding them directly in the class implementing the ITemplate interface, you would need to handle the DataBinding event of the combobox controls. In this case, you might need to pass a few more parameters to the class constructor.
Additionally, you can check this article:
http://www.telerik.com/help/aspnet-ajax/grid-operations-with-dropdownlist-in-edititemtemplate.html
Kind regards,
Iana
the Telerik team
You can handle the ItemDataBound event for the grid to bind the combobox controls.
But if you decide to place the code for binding them directly in the class implementing the ITemplate interface, you would need to handle the DataBinding event of the combobox controls. In this case, you might need to pass a few more parameters to the class constructor.
Additionally, you can check this article:
http://www.telerik.com/help/aspnet-ajax/grid-operations-with-dropdownlist-in-edititemtemplate.html
Kind regards,
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!
0
anirud
Top achievements
Rank 1
answered on 01 Apr 2011, 12:42 PM
Thanks Iana for response.B
ut i want to see my design and coding part. Then you will have a clear idea.
<%@ Page Title="" Language="C#" MasterPageFile="~/SMHRMaster.master" AutoEventWireup="true"
CodeFile="frm_Attendance.aspx.cs" Inherits="Payroll_frm_Attendance" %>
<
asp:Content
ID
=
"Content1"
ContentPlaceHolderID
=
"head"
runat
=
"Server"
>
</
asp:Content
>
<
asp:Content
ID
=
"Content2"
ContentPlaceHolderID
=
"cphDefault"
runat
=
"Server"
>
<
table
align
=
"center"
>
<
tr
>
<
td
colspan
=
"4"
>
<
asp:Label
ID
=
"lbl_Header"
runat
=
"server"
Text
=
"Attendence Details"
>
</
asp:Label
>
</
td
>
</
tr
>
<
tr
>
<
td
>
<
asp:Label
ID
=
"lbl_BusinessUnit"
runat
=
"server"
Text
=
"Business Unit"
>
</
asp:Label
>
</
td
>
<
td
>
<
b
>:</
b
>
</
td
>
<
td
>
<
telerik:RadComboBox
ID
=
"rcmb_AttBusinessUnit"
runat
=
"server"
AutoPostBack
=
"true"
>
</
telerik:RadComboBox
>
</
td
>
<
td
>
</
td
>
</
tr
>
<
tr
>
<
td
>
<
asp:Label
ID
=
"lbl_Period"
runat
=
"server"
Text
=
"Period"
>
</
asp:Label
>
</
td
>
<
td
>
<
b
>:</
b
>
</
td
>
<
td
>
<
telerik:RadComboBox
ID
=
"rcmb_AttPeriod"
runat
=
"server"
AutoPostBack
=
"true"
OnSelectedIndexChanged
=
"rcmb_Period_SelectedIndexChanged"
>
</
telerik:RadComboBox
>
</
td
>
<
td
>
</
td
>
</
tr
>
<
tr
runat
=
"server"
id
=
"tblr_AttPeriodElement"
visible
=
"false"
>
<
td
>
<
asp:Label
ID
=
"lbl_PeriodElement"
runat
=
"server"
Text
=
"Period Element"
>
</
asp:Label
>
</
td
>
<
td
>
<
b
>:</
b
>
</
td
>
<
td
>
<
telerik:RadComboBox
ID
=
"rcmb_AttPeriodElement"
runat
=
"server"
AutoPostBack
=
"true"
OnSelectedIndexChanged
=
"rcmb_AttPeriodElement_SelectedIndexChanged"
>
</
telerik:RadComboBox
>
</
td
>
<
td
>
</
td
>
</
tr
>
</
table
>
<
table
align
=
"center"
>
<
tr
>
<
td
align
=
"center"
>
<
telerik:RadGrid
ID
=
"rg_Attendence"
runat
=
"server"
AutoGenerateColumns
=
"false"
GridLines
=
"None"
Width
=
"750px"
OnItemDataBound
=
"rg_Attendence_ItemDataBound"
OnPreRender
=
"rg_Attendence_PreRender"
EnableViewState
=
"false"
OnNeedDataSource
=
"rg_Attendence_NeedDataSource"
onitemcreated
=
"rg_Attendence_ItemCreated"
>
<
ClientSettings
>
<
Scrolling
AllowScroll
=
"true"
UseStaticHeaders
=
"true"
SaveScrollPosition
=
"true"
FrozenColumnsCount
=
"1"
/>
</
ClientSettings
>
<
MasterTableView
Width
=
"100%"
EnableColumnsViewState
=
"false"
EnableViewState
=
"false"
>
<
Columns
>
<
telerik:GridTemplateColumn
Visible
=
"false"
>
<
ItemTemplate
>
<
asp:Label
ID
=
"lbl_Empid"
runat
=
"server"
Text='<%# Eval("ATTENDANCE_EMP_ID") %>'>
</
asp:Label
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
Visible
=
"true"
HeaderText
=
"Employee Name"
>
<
ItemTemplate
>
<
asp:Label
ID
=
"lbl_Name"
runat
=
"server"
Text='<%# Eval("ATTENDANCE_EMP_NAME") %>'>
</
asp:Label
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
</
td
>
</
tr
>
<
tr
>
<
td
align
=
"center"
>
<
asp:Button
ID
=
"btn_Save"
runat
=
"server"
Text
=
"Save"
OnClick
=
"btn_Save_Click"
Visible
=
"false"
/>
<
asp:Button
ID
=
"btn_Finalize"
runat
=
"server"
Text
=
"Finalize"
OnClick
=
"btn_Save_Click"
Visible
=
"false"
/>
</
td
>
</
tr
>
</
table
>
</
asp:Content
>
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Data;
using
SMHR;
using
Telerik.Web.UI;
public
partial
class
Payroll_frm_Attendance : System.Web.UI.Page
{
SMHR_PAYROLL _obj_smhr_payroll;
SMHR_LOGININFO _obj_SMHR_LoginInfo;
SMHR_EMPLOYEE _obj_smhr_Employee;
SMHR_ATTENDANCE _obj_Smhr_Attendance;
SMHR_PERIODDTL _obj_Smhr_Prddtl;
RadComboBox rcmbList =
new
RadComboBox();
DataTable dt_ds=
new
DataTable();
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!Page.IsPostBack)
{
loadDropdown();
}
}
protected
void
loadDropdown()
{
try
{
rcmb_AttBusinessUnit.Items.Clear();
_obj_SMHR_LoginInfo =
new
SMHR_LOGININFO();
_obj_SMHR_LoginInfo.ORGANISATION_ID = Convert.ToInt32(Session[
"ORG_ID"
]);
_obj_SMHR_LoginInfo.LOGIN_ID = Convert.ToInt32(Session[
"USER_ID"
]);
DataTable dt_BUDetails = BLL.get_Business_Units(_obj_SMHR_LoginInfo);
rcmb_AttBusinessUnit.DataSource = dt_BUDetails;
rcmb_AttBusinessUnit.DataTextField =
"BUSINESSUNIT_CODE"
;
rcmb_AttBusinessUnit.DataValueField =
"BUSINESSUNIT_ID"
;
rcmb_AttBusinessUnit.DataBind();
rcmb_AttBusinessUnit.Items.Insert(0,
new
Telerik.Web.UI.RadComboBoxItem(
"Select"
,
"-1"
));
SMHR_PERIOD _obj_smhr_period =
new
SMHR_PERIOD();
DataTable dt_Details =
new
DataTable();
_obj_smhr_period.OPERATION = operation.Select;
_obj_smhr_period.ORGANISATION_ID = Convert.ToInt32(Session[
"ORG_ID"
]);
dt_Details = BLL.get_PeriodHeaderDetails(_obj_smhr_period);
rcmb_AttPeriod.DataSource = dt_Details;
rcmb_AttPeriod.DataValueField =
"PERIOD_ID"
;
rcmb_AttPeriod.DataTextField =
"PERIOD_NAME"
;
rcmb_AttPeriod.DataBind();
rcmb_AttPeriod.Items.Insert(0,
new
RadComboBoxItem(
"Select"
,
"-1"
));
}
catch
(Exception ex)
{
SMHR.BLL.Error_Log(Session[
"USER_ID"
].ToString(), ex.TargetSite.ToString(), ex.Message.Replace(
"'"
,
"''"
),
"frm_Attendence"
, ex.StackTrace, DateTime.Now);
Response.Redirect(
"~/Frm_ErrorPage.aspx"
);
return
;
}
}
protected
void
rcmb_Period_SelectedIndexChanged(
object
o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
{
try
{
_obj_smhr_payroll =
new
SMHR_PAYROLL();
_obj_smhr_payroll.PERIODDTLID = Convert.ToInt32(rcmb_AttPeriod.SelectedValue);
_obj_smhr_payroll.MODE = 28;
DataTable dt_Details = BLL.get_payrolltrans(_obj_smhr_payroll);
if
(dt_Details.Rows.Count != 0)
{
rcmb_AttPeriodElement.DataSource = dt_Details;
rcmb_AttPeriodElement.DataValueField =
"PRDDTL_ID"
;
rcmb_AttPeriodElement.DataTextField =
"PRDDTL_NAME"
;
rcmb_AttPeriodElement.DataBind();
rcmb_AttPeriodElement.Items.Insert(0,
new
RadComboBoxItem(
"Select"
));
tblr_AttPeriodElement.Visible =
true
;
}
else
{
tblr_AttPeriodElement.Visible =
false
;
}
}
catch
(Exception ex)
{
SMHR.BLL.Error_Log(Session[
"USER_ID"
].ToString(), ex.TargetSite.ToString(), ex.Message.Replace(
"'"
,
"''"
),
"frm_Attendence"
, ex.StackTrace, DateTime.Now);
Response.Redirect(
"~/Frm_ErrorPage.aspx"
);
return
;
}
}
protected
void
btn_Save_Click(
object
sender, EventArgs e)
{
DataTable dt_NoOfDays = Dal.ExecuteQuery(
"SELECT DATEDIFF(DD,PRDDTL_STARTDATE,PRDDTL_ENDDATE)+1 as NoOfDays FROM SMHR_PERIODDETAILS WHERE PRDDTL_ID='"
+ Convert.ToInt32(rcmb_AttPeriodElement.SelectedValue) +
"'"
);
bool
status =
false
;
string
str_PeriodElementMonth =
null
;
string
str_PeriodYear =
null
;
ViewState[
"chk_PostBack"
]=
"true"
;
string
str_CurrentDate = DateTime.Now.ToShortDateString();
string
[] str_Split = str_CurrentDate.Split(
new
char
[] {
'/'
});
string
str_Date = str_Split[1];
_obj_Smhr_Attendance =
new
SMHR_ATTENDANCE();
DataTable dt_NoOfDays1 = Dal.ExecuteQuery(
"SELECT DATEDIFF(DD,PRDDTL_STARTDATE,PRDDTL_ENDDATE)+1 as NoOfDays FROM SMHR_PERIODDETAILS WHERE PRDDTL_ID='"
+ Convert.ToInt32(rcmb_AttPeriodElement.SelectedValue) +
"'"
);
int
I_Days1 = Convert.ToInt32(dt_NoOfDays.Rows[0][0]);
SMHR_PERIOD _obj_smhr_Period =
new
SMHR_PERIOD();
_obj_smhr_Period.OPERATION = operation.Check1;
_obj_smhr_Period.PERIOD_ID = Convert.ToInt32(rcmb_AttPeriod.SelectedValue);
DataTable dt_Period = BLL.get_PeriodHeaderDetails(_obj_smhr_Period);
if
(dt_Period.Rows.Count != 0)
{
str_PeriodYear = Convert.ToString(dt_Period.Rows[0][0]);
}
SMHR_PERIODDTL _obj_smhr_PeriodDetails =
new
SMHR_PERIODDTL();
_obj_smhr_PeriodDetails.OPERATION = operation.Check1;
_obj_smhr_PeriodDetails.PRDDTL_ID = Convert.ToInt32(rcmb_AttPeriodElement.SelectedValue);
_obj_smhr_PeriodDetails.PRDDTL_PERIOD_ID = Convert.ToInt32(rcmb_AttPeriod.SelectedValue);
DataTable dt_PeriodDetails = BLL.get_PeriodDetails(_obj_smhr_PeriodDetails);
if
(dt_PeriodDetails.Rows.Count != 0)
{
str_PeriodElementMonth = Convert.ToString(dt_PeriodDetails.Rows[0][0]);
}
Label lbl_Empid =
new
Label();
for
(
int
I_GridCount = 0; I_GridCount <= rg_Attendence.Items.Count - 1; I_GridCount++)
{
lbl_Empid = rg_Attendence.Items[I_GridCount].FindControl(
"lbl_Empid"
)
as
Label;
for
(
int
I_GridColCount = 1; I_GridColCount <= Convert.ToInt32(I_Days1); I_GridColCount++)
{
rcmbList = rg_Attendence.Items[I_GridCount].FindControl(Convert.ToString(I_GridColCount))
as
RadComboBox;
string
str_DayCount = Convert.ToString(I_GridColCount);
string
str_Attendance = str_PeriodElementMonth +
"/"
+ str_DayCount +
"/"
+ str_PeriodYear +
" "
+ Convert.ToString(DateTime.Now.ToLongTimeString());
switch
(((Button)sender).ID.ToUpper())
{
case
"BTN_SAVE"
:
_obj_Smhr_Attendance.ATTENDANCE_BU_ID = Convert.ToInt32(rcmb_AttBusinessUnit.SelectedValue);
_obj_Smhr_Attendance.ATTENDANCE_PERIOD_DTL_ID = Convert.ToInt32(rcmb_AttPeriodElement.SelectedValue);
_obj_Smhr_Attendance.ATTENDANCE_DATE = Convert.ToDateTime(str_Attendance);
_obj_Smhr_Attendance.ATTENDANCE_EMP_ID = Convert.ToInt32(lbl_Empid.Text);
_obj_Smhr_Attendance.ORGANISATION_ID = Convert.ToInt32(Session[
"ORG_ID"
]);
_obj_Smhr_Attendance.OPERATION = operation.Validate;
DataTable dt_ChkAttendance = BLL.get_Attendance(_obj_Smhr_Attendance);
if
(dt_ChkAttendance.Rows.Count!=0)
{
if
(Convert.ToString(dt_ChkAttendance.Rows[0][
"ATTENDANCE_FINALIZE"
]) ==
"1"
)
{
}
else
{
_obj_Smhr_Attendance.OPERATION = operation.Update;
_obj_Smhr_Attendance.ATTENDANCE_MODE =
true
;
_obj_Smhr_Attendance.ATTENDANCE_FINALIZE = 0;
_obj_Smhr_Attendance.ATTENDANCE_BU_ID = Convert.ToInt32(rcmb_AttBusinessUnit.SelectedValue);
_obj_Smhr_Attendance.ATTENDANCE_PERIOD_DTL_ID = Convert.ToInt32(rcmb_AttPeriodElement.SelectedValue);
_obj_Smhr_Attendance.ATTENDANCE_DATE = Convert.ToDateTime(str_Attendance);
_obj_Smhr_Attendance.ATTENDANCE_EMP_ID = Convert.ToInt32(lbl_Empid.Text);
_obj_Smhr_Attendance.ATTENDANCE_STATUS = Convert.ToString(rcmbList.SelectedValue);
_obj_Smhr_Attendance.ORGANISATION_ID = Convert.ToInt32(Session[
"ORG_ID"
]);
if
(BLL.set_Attendance(_obj_Smhr_Attendance))
{
status =
true
;
}
else
{
status =
false
;
}
}
}
else
{
_obj_Smhr_Attendance.ATTENDANCE_BU_ID = Convert.ToInt32(rcmb_AttBusinessUnit.SelectedValue);
_obj_Smhr_Attendance.ATTENDANCE_PERIOD_DTL_ID = Convert.ToInt32(rcmb_AttPeriodElement.SelectedValue);
_obj_Smhr_Attendance.ATTENDANCE_DATE = Convert.ToDateTime(str_Attendance);
_obj_Smhr_Attendance.ATTENDANCE_EMP_ID = Convert.ToInt32(lbl_Empid.Text);
_obj_Smhr_Attendance.ATTENDANCE_STATUS = Convert.ToString(rcmbList.SelectedValue);
_obj_Smhr_Attendance.ORGANISATION_ID = Convert.ToInt32(Session[
"ORG_ID"
]);
_obj_Smhr_Attendance.ATTENDANCE_FINALIZE = 0;
_obj_Smhr_Attendance.OPERATION = operation.Insert;
}
break
;
case
"BTN_FINALIZE"
:
_obj_Smhr_Attendance.ATTENDANCE_BU_ID = Convert.ToInt32(rcmb_AttBusinessUnit.SelectedValue);
_obj_Smhr_Attendance.ATTENDANCE_PERIOD_DTL_ID = Convert.ToInt32(rcmb_AttPeriodElement.SelectedValue);
_obj_Smhr_Attendance.ATTENDANCE_DATE = Convert.ToDateTime(str_Attendance);
_obj_Smhr_Attendance.ATTENDANCE_EMP_ID = Convert.ToInt32(lbl_Empid.Text);
_obj_Smhr_Attendance.ORGANISATION_ID = Convert.ToInt32(Session[
"ORG_ID"
]);
_obj_Smhr_Attendance.OPERATION = operation.Validate;
DataTable dt_ChkAttendance1 = BLL.get_Attendance(_obj_Smhr_Attendance);
if
(dt_ChkAttendance1.Rows.Count != 0)
{
if
(Convert.ToString(dt_ChkAttendance1.Rows[0][
"ATTENDANCE_FINALIZE"
]) ==
"1"
)
{
}
else
{
_obj_Smhr_Attendance =
new
SMHR_ATTENDANCE();
_obj_Smhr_Attendance.OPERATION = operation.Update;
_obj_Smhr_Attendance.ATTENDANCE_MODE =
false
;
_obj_Smhr_Attendance.ATTENDANCE_FINALIZE = 1;
_obj_Smhr_Attendance.ATTENDANCE_BU_ID = Convert.ToInt32(rcmb_AttBusinessUnit.SelectedValue);
_obj_Smhr_Attendance.ATTENDANCE_DATE = Convert.ToDateTime(str_Attendance);
if
(BLL.set_Attendance(_obj_Smhr_Attendance))
{
status =
true
;
}
else
{
status =
false
;
}
}
}
break
;
default
:
break
;
}
}
}
}
protected
void
btn_Finalize_Click(
object
sender, EventArgs e)
{
}
protected
void
rcmb_AttPeriodElement_SelectedIndexChanged(
object
o, RadComboBoxSelectedIndexChangedEventArgs e)
{
string
str_CurrentDate = DateTime.Now.ToShortDateString();
string
[] str_Split = str_CurrentDate.Split(
new
char
[] {
'/'
});
string
str_Month=str_Split[0];
string
str_Date = str_Split[1];
string
str_Year=str_Split[2];
_obj_Smhr_Prddtl =
new
SMHR_PERIODDTL();
_obj_Smhr_Prddtl.PRDDTL_ID = Convert.ToInt32(rcmb_AttPeriodElement.SelectedValue);
_obj_Smhr_Prddtl.OPERATION = operation.Select;
DataTable dt_Prddtl_EndDate = BLL.get_PeriodDetails(_obj_Smhr_Prddtl);
DateTime DT_Prddtl_EndDate = Convert.ToDateTime(dt_Prddtl_EndDate.Rows[0][
"PRDDTL_ENDDATE"
]);
string
str_Prddtl_EndDate = DT_Prddtl_EndDate.ToShortDateString();
string
[] str_Prddtl_EndDateSplit = str_Prddtl_EndDate.Split(
new
char
[] {
'/'
});
string
str_EndMonth = str_Prddtl_EndDateSplit[0];
string
str_EndDate=str_Prddtl_EndDateSplit[1];
string
str_EndYear = str_Prddtl_EndDateSplit[2];
btn_Save.Visible =
true
;
if
(Convert.ToInt32(str_EndYear) <= Convert.ToInt32(str_Year))
{
if
(Convert.ToInt32(str_EndMonth) <= Convert.ToInt32(str_Month))
{
btn_Finalize.Visible=
true
;
}
}
rg_Attendence.Visible =
true
;
loadGrid();
}
public
void
loadGrid()
{
//here i am creating the columns
DataTable dt_NoOfDays = Dal.ExecuteQuery(
"SELECT DATEDIFF(DD,PRDDTL_STARTDATE,PRDDTL_ENDDATE)+1 as NoOfDays FROM SMHR_PERIODDETAILS WHERE PRDDTL_ID='"
+ Convert.ToInt32(rcmb_AttPeriodElement.SelectedValue) +
"'"
);
int
I_Days = Convert.ToInt32(dt_NoOfDays.Rows[0][0]);
ViewState[
"NoOfDays"
] = Convert.ToString(I_Days);
for
(
int
I_ColumnCount = 1; I_ColumnCount <= I_Days; I_ColumnCount++)
{
GridTemplateColumn gridtemplatecolumn =
new
GridTemplateColumn();
gridtemplatecolumn.ItemTemplate =
new
MyTemplate(Convert.ToString(I_ColumnCount));
gridtemplatecolumn.DataField = Convert.ToString(
"LEAVE_STATUS"
);
gridtemplatecolumn.HeaderText = Convert.ToString(I_ColumnCount);
gridtemplatecolumn.UniqueName = Convert.ToString(I_ColumnCount);
this
.rg_Attendence.MasterTableView.Columns.Add(gridtemplatecolumn);
ViewState[
"grid_DayCount"
] = Convert.ToString(I_ColumnCount);
string
grid_DayCount = Convert.ToString(ViewState[
"grid_DayCount"
]);
try
{
_obj_Smhr_Attendance =
new
SMHR_ATTENDANCE();
_obj_Smhr_Attendance.OPERATION = operation.GetAttendance;
_obj_Smhr_Attendance.ATTENDANCE_BU_ID = Convert.ToInt32(rcmb_AttBusinessUnit.SelectedItem.Value);
_obj_Smhr_Attendance.ATTENDANCE_PERIOD_DTL_ID = Convert.ToInt32(rcmb_AttPeriodElement.SelectedValue);
DataTable DT_Employee =
new
DataTable();
DT_Employee = BLL.get_Attendance(_obj_Smhr_Attendance);
if
(DT_Employee.Rows.Count != 0)
{
rg_Attendence.DataSource = DT_Employee;
rg_Attendence.DataBind();
}
else
{
_obj_Smhr_Attendance =
new
SMHR_ATTENDANCE();
_obj_Smhr_Attendance.ATTENDANCE_BU_ID = Convert.ToInt32(rcmb_AttBusinessUnit.SelectedValue);
_obj_Smhr_Attendance.ORGANISATION_ID = Convert.ToInt32(Session[
"ORG_ID"
]);
_obj_Smhr_Attendance.OPERATION = operation.SELECTEMPLOYEE;
DataTable dt_Emp = BLL.get_Attendance(_obj_Smhr_Attendance);
if
(dt_Emp.Rows.Count != 0)
{
rg_Attendence.DataSource = dt_Emp;
rg_Attendence.DataBind();
}
}
}
catch
(Exception ex)
{
SMHR.BLL.Error_Log(Session[
"USER_ID"
].ToString(), ex.TargetSite.ToString(), ex.Message.Replace(
"'"
,
"''"
),
"frm_Attendance"
, ex.StackTrace, DateTime.Now);
Response.Redirect(
"~/Frm_ErrorPage.aspx"
);
return
;
}
}
loadEmployees();
}
public
class
MyTemplate : ITemplate
{
//here i am instantiating columns and radcombobox
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);
lblControl.Items.Insert(0,
new
RadComboBoxItem(
"Select"
,
"Select"
));
lblControl.Items.Insert(1,
new
RadComboBoxItem(
"P"
,
"P"
));
lblControl.Items.Insert(2,
new
RadComboBoxItem(
"A"
,
"A"
));
lblControl.Items.Insert(3,
new
RadComboBoxItem(
"L"
,
"L"
));
lblControl.Items.Insert(4,
new
RadComboBoxItem(
"W"
,
"W"
));
lblControl.Items.Insert(5,
new
RadComboBoxItem(
"T"
,
"T"
));
lblControl.Items.Insert(6,
new
RadComboBoxItem(
"C"
,
"C"
));
lblControl.Items.Insert(7,
new
RadComboBoxItem(
"H"
,
"H"
));
lblControl.Items.Insert(8,
new
RadComboBoxItem(
"HD"
,
"HD"
));
lblControl.EnableViewState =
false
;
}
}
protected
void
loadEmployees()
{
//here i am binding the datatable to rad grid
try
{
int
i = 0;
_obj_Smhr_Attendance =
new
SMHR_ATTENDANCE();
_obj_Smhr_Attendance.OPERATION = operation.GetAttendance;
_obj_Smhr_Attendance.ATTENDANCE_BU_ID = Convert.ToInt32(rcmb_AttBusinessUnit.SelectedItem.Value);
_obj_Smhr_Attendance.ATTENDANCE_PERIOD_DTL_ID = Convert.ToInt32(rcmb_AttPeriodElement.SelectedValue);
DataTable DT_Employee =
new
DataTable();
DT_Employee = BLL.get_Attendance(_obj_Smhr_Attendance);
ViewState[
"DT_Employee"
] = DT_Employee;
if
(DT_Employee.Rows.Count != 0)
{
rg_Attendence.DataSource = DT_Employee;
rg_Attendence.DataBind();
DataTable dt_NoOfDays = Dal.ExecuteQuery(
"SELECT DATEDIFF(DD,PRDDTL_STARTDATE,PRDDTL_ENDDATE)+1 as NoOfDays FROM SMHR_PERIODDETAILS WHERE PRDDTL_ID='"
+ Convert.ToInt32(rcmb_AttPeriodElement.SelectedValue) +
"'"
);
int
I_Days = Convert.ToInt32(dt_NoOfDays.Rows[0][0]);
for
(
int
I_ColumnCount = 1; I_ColumnCount <= I_Days; I_ColumnCount++)
{
for
(i = 0; i <= rg_Attendence.Items.Count - 1; i++)
{
rcmbList = rg_Attendence.Items[i].FindControl(Convert.ToString(I_ColumnCount))
as
RadComboBox;
if
(Convert.ToString(Convert.ToString(DT_Employee.Rows[i][I_ColumnCount])).Trim() !=
""
)
{
if
((Convert.ToString(Convert.ToString(DT_Employee.Rows[i][I_ColumnCount])).Substring(0,1)).Trim() ==
"P"
)
{
rcmbList.SelectedIndex = rcmbList.FindItemIndexByValue(Convert.ToString(
"P"
));
}
else
if
((Convert.ToString(Convert.ToString(DT_Employee.Rows[i][I_ColumnCount])).Substring(0,1)).Trim() ==
"A"
)
{
rcmbList.SelectedIndex = rcmbList.FindItemIndexByValue(Convert.ToString(
"A"
));
}
else
if
((Convert.ToString(Convert.ToString(DT_Employee.Rows[i][I_ColumnCount])).Substring(0, 1)).Trim() ==
"L"
)
{
rcmbList.SelectedIndex = rcmbList.FindItemIndexByValue(Convert.ToString(
"L"
));
}
else
if
((Convert.ToString(Convert.ToString(DT_Employee.Rows[i][I_ColumnCount])).Substring(0, 1)).Trim() ==
"W"
)
{
rcmbList.SelectedIndex = rcmbList.FindItemIndexByValue(Convert.ToString(
"W"
));
}
else
if
((Convert.ToString(Convert.ToString(DT_Employee.Rows[i][I_ColumnCount])).Substring(0, 1)).Trim() ==
"T"
)
{
rcmbList.SelectedIndex = rcmbList.FindItemIndexByValue(Convert.ToString(
"T"
));
}
else
if
((Convert.ToString(Convert.ToString(DT_Employee.Rows[i][I_ColumnCount])).Substring(0, 1)).Trim() ==
"C"
)
{
rcmbList.SelectedIndex = rcmbList.FindItemIndexByValue(Convert.ToString(
"C"
));
}
else
if
((Convert.ToString(Convert.ToString(DT_Employee.Rows[i][I_ColumnCount])).Substring(0, 1)).Trim() ==
"H"
)
{
rcmbList.SelectedIndex = rcmbList.FindItemIndexByValue(Convert.ToString(
"H"
));
}
string
str = Convert.ToString(DT_Employee.Rows[i][I_ColumnCount]);
string
[] s1 = str.Split(
new
char
[] {
'-'
});
if
(s1[1] ==
"1"
)
{
rcmbList.Enabled =
false
;
}
}
else
{
rcmbList.SelectedIndex=1;
string
str_CurrentDate = DateTime.Now.ToShortDateString();
string
[] str_Split = str_CurrentDate.Split(
new
char
[] {
'/'
});
string
str_Date = str_Split[1];
if
(Convert.ToInt32(I_ColumnCount) > Convert.ToInt32(str_Date))
{
rcmbList.Enabled =
false
;
}
}
}
}
}
else
{
DataTable dt_NoOfDays = Dal.ExecuteQuery(
"SELECT DATEDIFF(DD,PRDDTL_STARTDATE,PRDDTL_ENDDATE)+1 as NoOfDays FROM SMHR_PERIODDETAILS WHERE PRDDTL_ID='"
+ Convert.ToInt32(rcmb_AttPeriodElement.SelectedValue) +
"'"
);
int
I_Days = Convert.ToInt32(dt_NoOfDays.Rows[0][0]);
for
(
int
I_ColumnCount = 1; I_ColumnCount <= I_Days; I_ColumnCount++)
{
for
(i = 0; i <= rg_Attendence.Items.Count - 1; i++)
{
rcmbList = rg_Attendence.Items[i].FindControl(Convert.ToString(I_ColumnCount))
as
RadComboBox;
rcmbList.SelectedIndex = 1;
string
str_MonthNo = DateTime.Now.Month.ToString();
if
(Convert.ToInt32(rcmb_AttPeriodElement.SelectedIndex)>Convert.ToInt32(str_MonthNo))
{
rcmbList.Enabled=
false
;
btn_Finalize.Enabled =
false
;
btn_Save.Enabled =
false
;
}
}
}
}
}
catch
(Exception ex)
{
SMHR.BLL.Error_Log(Session[
"USER_ID"
].ToString(), ex.TargetSite.ToString(), ex.Message.Replace(
"'"
,
"''"
),
"frm_Attendance"
, ex.StackTrace, DateTime.Now);
Response.Redirect(
"~/Frm_ErrorPage.aspx"
);
return
;
}
}
}
0
Hi anirud,
I reviewed your code and was able to understand your scenario. However you should know that:
- RadGrid does not support having declarative columns as well as columns added dynamically. You should either add all columns declaratively or dynamically.
- If you have GridTemplateColumns added dynamically, you should do all the coding on Page_Init. In this case the whole grid should be created dynamically on Page_Init.
Therefore I suggest that you follow the steps described in this topic in order to achieve your goal. There the grid columns are changed based on DropDownList selection.
Kind regards,
Iana
the Telerik team
I reviewed your code and was able to understand your scenario. However you should know that:
- RadGrid does not support having declarative columns as well as columns added dynamically. You should either add all columns declaratively or dynamically.
- If you have GridTemplateColumns added dynamically, you should do all the coding on Page_Init. In this case the whole grid should be created dynamically on Page_Init.
Therefore I suggest that you follow the steps described in this topic in order to achieve your goal. There the grid columns are changed based on DropDownList selection.
Kind regards,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
anirud
Top achievements
Rank 1
answered on 05 Apr 2011, 04:11 PM
Hi Iana,
Thanks for reference code but that is nice as far as columns are concerned. When I try to created radcomboboxes inside Rad Grid in each of its cells the issue starts from there. Also I am facing problem in handling the postback from those comboboxes inside grid. Futhere I have save button in order to save the text selected on those comboboxes which are inside grid in database(again postback).
Due these total of 3 postbacks i am unable to capture the text selected on those comboboxes which are inside grid.
Thanks
Thanks for reference code but that is nice as far as columns are concerned. When I try to created radcomboboxes inside Rad Grid in each of its cells the issue starts from there. Also I am facing problem in handling the postback from those comboboxes inside grid. Futhere I have save button in order to save the text selected on those comboboxes which are inside grid in database(again postback).
Due these total of 3 postbacks i am unable to capture the text selected on those comboboxes which are inside grid.
Thanks
0
Hi anirud,
If I properly understand you are adding the comboboxes in each cell for all rows in the grid, right? And the problem is that you cannot access them in the save button Click event handler?
Kind regards,
Iana
the Telerik team
If I properly understand you are adding the comboboxes in each cell for all rows in the grid, right? And the problem is that you cannot access them in the save button Click event handler?
Kind regards,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
anirud
Top achievements
Rank 1
answered on 27 Apr 2011, 07:46 AM
HI lana,
yes you are right. I need radcomboboxes in that way only. But due to postbacks at multiple levels i am losing the rad grid every time .
For ex, at time of paging,click on button etc.
Thanks.
yes you are right. I need radcomboboxes in that way only. But due to postbacks at multiple levels i am losing the rad grid every time .
For ex, at time of paging,click on button etc.
Thanks.
0
Hi anirud,
Try creating the grid with the template columns entire in code behind, on Page_Init as described in the below articles and see if it makes any difference:
http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html
http://www.telerik.com/help/aspnet-ajax/grid-changing-structure-dynamically.html
Regards,
Iana
the Telerik team
Try creating the grid with the template columns entire in code behind, on Page_Init as described in the below articles and see if it makes any difference:
http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html
http://www.telerik.com/help/aspnet-ajax/grid-changing-structure-dynamically.html
Regards,
Iana
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Namrata
Top achievements
Rank 1
answered on 09 May 2015, 10:33 AM
i want to make student attendance from. i want to display the number of days on change of month in grid view
like this
student list 1/05/2015 2/05/2015 till last day
abc p p a
xyz p p p
0
Brett
Top achievements
Rank 1
answered on 12 May 2015, 04:14 PM
I haven't reviewed all of your issues, but since you're using the ITemplate.InitateIn (seemingly correctly)..
It seems that the only thing you you're missing is the adding/assigning of the OnBinding, and OnSelectedIndexChanged an event handlers of the control you're adding to the container in the InitiateIn method.
public class MyTemplate : ITemplate
{
//here i am instantiating columns and radcombobox
protected RadComboBox lblControl;
public string colname;
public MyTemplate(string cName)
{
colname = cName;
}
public void InstantiateIn(System.Web.UI.Control container)
{
lblControl = new RadComboBox();
lblControl.OnBinding += RadComboBox_OnBinding;
lblControl.OnSelectedIndexChanged += RadComboBox_OnSelectedIndexChanged;
lblControl.ID = colname;
lblControl.Items.Insert(0, new RadComboBoxItem("Please Select", "None"));
lblControl.EnableViewState = false;
container.Controls.Add(lblControl);
}
protected void RadComboBox_OnBinding(object sender, System.EventArgs e)
{
// sender is a control (RadComboBox) that implements the INamingContainer which can be casted to 'GridDataItem'..
// GridDataItem.DataItem can be casted to your DataModel, or the instance/data of the property that correlates to the "Field" Property of the GridTemplateColumn you defined in your Code-Behind
RadComboBox control = (RadComboBox)sender;
GridDataItem container = ((GridDataItem)control.NamingContainer);
YouDataModel data = ((YourDataModel)container.DataItem)
//lblControl.Items.Insert(1, new RadComboBoxItem("P", "P"));
//lblControl.Items.Insert(2, new RadComboBoxItem("A", "A"));
//lblControl.Items.Insert(3, new RadComboBoxItem("L", "L"));
//lblControl.Items.Insert(4, new RadComboBoxItem("W", "W"));
//lblControl.Items.Insert(5, new RadComboBoxItem("T", "T"));
//lblControl.Items.Insert(6, new RadComboBoxItem("C", "C"));
//lblControl.Items.Insert(7, new RadComboBoxItem("H", "H"));
//lblControl.Items.Insert(8, new RadComboBoxItem("HD", "HD"));
}
protected void RadComboBox_OnSelectedIndexChanged(object sender, System.EventArgs e)
{
// do something here...
// A good idea would be to to create your OWN delegate event in this class, and raise it here.. you can then handle the event in the code-behind by assigning an event handler method to the delegate in your loadGrid method.
}
}
It seems that the only thing you you're missing is the adding/assigning of the OnBinding, and OnSelectedIndexChanged an event handlers of the control you're adding to the container in the InitiateIn method.
public class MyTemplate : ITemplate
{
//here i am instantiating columns and radcombobox
protected RadComboBox lblControl;
public string colname;
public MyTemplate(string cName)
{
colname = cName;
}
public void InstantiateIn(System.Web.UI.Control container)
{
lblControl = new RadComboBox();
lblControl.OnBinding += RadComboBox_OnBinding;
lblControl.OnSelectedIndexChanged += RadComboBox_OnSelectedIndexChanged;
lblControl.ID = colname;
lblControl.Items.Insert(0, new RadComboBoxItem("Please Select", "None"));
lblControl.EnableViewState = false;
container.Controls.Add(lblControl);
}
protected void RadComboBox_OnBinding(object sender, System.EventArgs e)
{
// sender is a control (RadComboBox) that implements the INamingContainer which can be casted to 'GridDataItem'..
// GridDataItem.DataItem can be casted to your DataModel, or the instance/data of the property that correlates to the "Field" Property of the GridTemplateColumn you defined in your Code-Behind
RadComboBox control = (RadComboBox)sender;
GridDataItem container = ((GridDataItem)control.NamingContainer);
YouDataModel data = ((YourDataModel)container.DataItem)
//lblControl.Items.Insert(1, new RadComboBoxItem("P", "P"));
//lblControl.Items.Insert(2, new RadComboBoxItem("A", "A"));
//lblControl.Items.Insert(3, new RadComboBoxItem("L", "L"));
//lblControl.Items.Insert(4, new RadComboBoxItem("W", "W"));
//lblControl.Items.Insert(5, new RadComboBoxItem("T", "T"));
//lblControl.Items.Insert(6, new RadComboBoxItem("C", "C"));
//lblControl.Items.Insert(7, new RadComboBoxItem("H", "H"));
//lblControl.Items.Insert(8, new RadComboBoxItem("HD", "HD"));
}
protected void RadComboBox_OnSelectedIndexChanged(object sender, System.EventArgs e)
{
// do something here...
// A good idea would be to to create your OWN delegate event in this class, and raise it here.. you can then handle the event in the code-behind by assigning an event handler method to the delegate in your loadGrid method.
}
}
0
saheste
Top achievements
Rank 1
answered on 26 May 2015, 09:32 PM
hi
i have the same problem
but i dont resolve i did all of them in your answers but dont fix
thanks