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

Inserting griddataitem into a RadGrid item template control

2 Answers 224 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bill
Top achievements
Rank 1
Bill asked on 22 Sep 2011, 10:47 PM
Hi all,

Right now I am pulling values from 2 columns in a RadGrid control, and programitcally putting them into a table cell. Then, I am adding that table cell into a gridataitem, programitcally.

What I want to do, is then insert that griddataitem into a control within an item tempalte that contains a header and a footer.

Here is a sample of what I am doing:
<P>GridDataItem item = e.Item as GridDataItem;<BR></P>
<P>string totala =
item.OwnerTableView.DataKeyValues[dataItem.ItemIndex]["total1"].ToString();<BR>string
totalb =
item.OwnerTableView.DataKeyValues[dataItem.ItemIndex]["total2"].ToString();<BR></P>
<P>double a = double.Parse(totala.ToString());<BR>double b =
double.Parse(totalb.ToString());<BR>double c = a + b;</P>
<P><BR>TableCell tc = new TableCell();<BR>tc.Text = c.ToString("c");</P>
<P><BR>item.Cells.Add(tc);<BR></P>

Any ideas?



2 Answers, 1 is accepted

Sort by
0
Bill
Top achievements
Rank 1
answered on 23 Sep 2011, 02:41 AM
Can anyone help please?
0
Princy
Top achievements
Rank 2
answered on 23 Sep 2011, 09:32 AM
Hello Bill,

You can access the control inside ItemTemplate using FindControl() method and assign the values like below.

C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
 {
         //your code
         TextBox txt = (TextBox)item1.FindControl("txt");
         txt.Text = c.ToString();
 }

Thanks,
Princy.
Tags
Grid
Asked by
Bill
Top achievements
Rank 1
Answers by
Bill
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or