4 Answers, 1 is accepted
0
Jayesh Goyani
Top achievements
Rank 2
answered on 07 Jul 2012, 06:37 AM
Hello Dave,
Thanks,
Jayesh Goyani
protected
void
RadGrid2_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
GridDataItem item = e.Item
as
GridDataItem;
Label label1 = item.FindControl(
"label1"
)
as
Label;
// Using Data Key
DateTime dt =Convert.ToDateTime(item.GetDataKeyValue(
"ShipDate"
).ToString());
label1.Text = Convert.ToInt32((DateTime.Now.Subtract(Convert.ToDateTime(item.GetDataKeyValue(
"ShipDate"
).ToString())).Days / 365)).ToString();
// this logic is not perfect -- this is only for reference
//OR
// Using DataItem / Assigned Datasource
DataRowView dr = item.DataItem
as
DataRowView;
label1.Text = Convert.ToInt32((DateTime.Now.Subtract(Convert.ToDateTime(dr[
"ShipDate"
].ToString())).Days / 365)).ToString();
// this logic is not perfect -- this is only for reference
}
}
protected
void
RadGrid2_NeedDataSource(
object
sender, GridNeedDataSourceEventArgs e)
{
DataTable dt =
new
DataTable();
dt.Columns.Add(
"Shipper"
,
typeof
(
string
));
dt.Columns.Add(
"ShipDate"
,
typeof
(DateTime));
dt.Rows.Add(
"Shipper1"
, DateTime.Now.AddYears(-1));
dt.Rows.Add(
"Shipper2"
, DateTime.Now.AddYears(-2));
dt.Rows.Add(
"Shipper3"
, DateTime.Now.AddYears(-3));
dt.Rows.Add(
"Shipper1"
, DateTime.Now.AddYears(-1));
dt.Rows.Add(
"Shipper2"
, DateTime.Now.AddYears(-2));
dt.Rows.Add(
"Shipper3"
, DateTime.Now.AddYears(-3));
RadGrid2.DataSource = dt;
}
<
MasterTableView
DataKeyNames
=
"ShipDate"
>
<
Columns
>
<
telerik:GridTemplateColumn
HeaderText
=
"Age"
>
<
ItemTemplate
>
<
asp:Label
ID
=
"label1"
runat
=
"server"
></
asp:Label
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
</
MasterTableView
>
Thanks,
Jayesh Goyani
0
Dave
Top achievements
Rank 1
answered on 08 Jul 2012, 12:29 AM
I am real sorry I do not understand this?
Can someone please break it down a bit more.
I added a template field for AGE I gave it a label called label115
I then added the following piece of code to the cs file....
Can someone please break it down a bit more.
I added a template field for AGE I gave it a label called label115
<
telerik:GridTemplateColumn
FilterControlAltText
=
"Filter OfficerAge column"
HeaderText
=
"Age"
UniqueName
=
"OfficerAge"
>
<
ItemTemplate
>
<
asp:Label
ID
=
"label115"
runat
=
"server"
></
asp:Label
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
I then added the following piece of code to the cs file....
protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = e.Item as GridDataItem;
Label label1 = item.FindControl("label115") as Label;
// Using Data Key
DateTime dt = Convert.ToDateTime(item.GetDataKeyValue("emp_DOB").ToString());
label1.Text = Convert.ToInt32((DateTime.Now.Subtract(Convert.ToDateTime(item.GetDataKeyValue("emp_DOB").ToString())).Days / 365)).ToString(); // this logic is not perfect -- this is only for reference
}
}
0
Dave
Top achievements
Rank 1
answered on 09 Jul 2012, 02:58 AM
I am really stumped on this and could reallty use some help.
I just need the Template field OfficerAge to = the age of the emp_DOB officer?
What am I doing wrong, please first grader teacher style and show me please.
Matt
I just need the Template field OfficerAge to = the age of the emp_DOB officer?
What am I doing wrong, please first grader teacher style and show me please.
Matt
0
Jayesh Goyani
Top achievements
Rank 2
answered on 09 Jul 2012, 05:51 AM
Hello,
Please add below code.
Thanks,
Jayesh Goyani
Please add below code.
<
MasterTableView
DataKeyNames
=
"emp_DOB"
>
Thanks,
Jayesh Goyani