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

Access to values of GridTemplateColumn

5 Answers 563 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Xorv
Top achievements
Rank 2
Xorv asked on 19 Jan 2012, 02:32 PM
Hi,

I have a radgrid.
<telerik:RadGrid ID="RGStyleGuideRestrictions" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" EnableEmbeddedSkins="False" Skin="Vista">
     <MasterTableView  EditMode="InPlace" DataSourceID="SqlDataSource1"  DataKeyNames="StartDate">
            <Columns>
              <telerik:GridBoundColumn DataField="StartDate" HeaderText="Start Date" UniqueName="StartDate"
               </telerik:GridBoundColumn>
               <telerik:GridTemplateColumn  UniqueName="TemplateColumn" HeaderText="Condition">
                <ItemTemplate>
                    <asp:Label ID= "lblCondition" runat = "server" ></asp:Label>
                </ItemTemplate>
               </telerik:GridTemplateColumn>
             </Columns>
      </MasterTableView>
</telerik:RadGrid>

Inside that few 'GridBoundColumn' are there and also 'GridTemplateCoulmn' are there.
When in server side, I want to access the values inside a 'GridBoundColumn', I can use 'datafield' property to get that. Like this:-
foreach (GridDataItem allitem in RadGrid1.MasterTableView.Items)
{
   if ((allitem["StartDate"].Text.ToString();
}

Now, my question is how to access values inside a 'GridTemplateColumn', as mentioned in aspx file above.
I want to access each value of that column, so that I could do some checking on each value and then move ahead.

Please tell what to do.
I would appreciate it.

thanks a ton:)

5 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 19 Jan 2012, 02:39 PM
Hello,

foreach (GridDataItem allitem in RadGrid1.MasterTableView.Items)
       {
            string str =  allitem["StartDate"].Text.ToString();
            string str1 = (allitem.FindControl("lblCondition") as Label).Text;
       }


Thanks,
Jayesh Goyani
0
Accepted
Princy
Top achievements
Rank 2
answered on 19 Jan 2012, 02:39 PM
Hello,

Try the following code.
C#:
protected void grid_ItemDataBound(object sender, GridItemEventArgs e)
{
 if (e.Item is GridDataItem)
 {
   GridDataItem item = (GridDataItem)e.Item;
   Label lbl = (Label)item.FindControl("Label1");
   string val = lbl.Text;
 }
}

Thanks,
Princy.
0
Xorv
Top achievements
Rank 2
answered on 19 Jan 2012, 02:55 PM
This works thanks : )
Thanks a lot PRINCY and JAYESH !!
Also, there is one more soultion. I can use "UniqueName" property of' GridTemplateView', to access the values inside it.

:)
all smilezzz

XORV
0
Xorv
Top achievements
Rank 2
answered on 21 Jan 2012, 07:01 PM
@ JAYESH


Man u rock. Literally, u saved my arse. I owe your help very much. Seriously, m so happy. Would tell u later how ur simple solution made my day.

Thanks a ton'god bless
0
Jayesh Goyani
Top achievements
Rank 2
answered on 21 Jan 2012, 07:14 PM
Hello Xorv,

Its ok man.
its my pleasure.

Thanks to you also.

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Xorv
Top achievements
Rank 2
Answers by
Jayesh Goyani
Top achievements
Rank 2
Princy
Top achievements
Rank 2
Xorv
Top achievements
Rank 2
Share this question
or