Access to values of GridTemplateColumn

6 posts, 2 answers
  1. Xorv
    Xorv avatar
    19 posts
    Member since:
    Jan 2012

    Posted 19 Jan 2012 Link to this post

    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:)

  2. Answer
    Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 19 Jan 2012 Link to this post

    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
  3. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 19 Jan 2012 Link to this post

    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.
  4. Xorv
    Xorv avatar
    19 posts
    Member since:
    Jan 2012

    Posted 19 Jan 2012 Link to this post

    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
  5. Xorv
    Xorv avatar
    19 posts
    Member since:
    Jan 2012

    Posted 21 Jan 2012 Link to this post

    @ 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
  6. Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 21 Jan 2012 Link to this post

    Hello Xorv,

    Its ok man.
    its my pleasure.

    Thanks to you also.

    Thanks,
    Jayesh Goyani
Back to Top