GridTemplateColumn not working on selectedindexchanged event

3 posts, 0 answers
  1. Vitaly
    Vitaly  avatar
    78 posts
    Member since:
    Aug 2011

    Posted 08 Oct 2013 Link to this post

    Good afternoon,
    I have following code inside my radgrid:
     <telerik:GridTemplateColumn HeaderText="Job" DataField="JOB" UniqueName="JOB" ReadOnly="True" SortExpression="JOB" >
      <HeaderStyle Width="50px" />
      <ItemStyle Width="50px" />
       <ItemTemplate>
      <asp:Label ID="lblJob" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.JOB") %>'> </asp:Label>
      <telerik:RadToolTip ID="RadToolTip1" runat="server" TargetControlID="lblJob"
       RelativeTo="Element" Position="MiddleRight" Font-Size="14" Font-Bold="true" Font-Italic="true" RenderInPageRoot="true"   Animation="Fade"  HideEvent="LeaveToolTip">
    JOB EFFECTIVE DATE:
    <%# DataBinder.Eval(Container, "DataItem.EFF_DATE","{0:MM/dd/yyyy}")%> <br />
    JOB END DATE:
    <%# DataBinder.Eval(Container, "DataItem.END_DATE","{0:MM/dd/yyyy}")%>  <br />
    DATE RESTRICTION FLAG:
    <%# DataBinder.Eval(Container, "DataItem.DATE_RESTRICT")%>
    </telerik:RadToolTip>
    </ItemTemplate>
    </telerik:GridTemplateColumn>

    On SelectedIndexChanged  event I try to grab value from GridTemplateColumn(JOB) like this:
    RadGrid ReportGrid = (RadGrid)dataReport.FindItemByValue("ReportData").FindControl("JobReportGrid");
     JobDetail = ReportGrid.SelectedItems[0].Cells[2].Text;

    And for some reason I am getting spaces.
    For regular gridboundcolumn this logic works just fine.

    Please help me,
    Thanks so much,
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 09 Oct 2013 Link to this post

    HI Vitaly,

    I guess you want to access the label value of the TemplateColumn on the SelectedIndexChanged event.Please try the following code snippet.

    C#:
    protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
       {
           GridDataItem selectedItem = (GridDataItem)RadGrid1.SelectedItems[0];//accessing selected row
           Label lbl = (Label)selectedItem.FindControl("lblJob"); // Accessing the label in template column
           string val = lbl.Text;//getting value
       }

    Thanks,
    Princy
  3. Vitaly
    Vitaly  avatar
    78 posts
    Member since:
    Aug 2011

    Posted 09 Oct 2013 Link to this post

    Thanks so much for your help.
    It works.
Back to Top