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

GridTemplateColumn not working on selectedindexchanged event

2 Answers 20 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Vitaly
Top achievements
Rank 1
Vitaly asked on 08 Oct 2013, 04:56 PM
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 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 09 Oct 2013, 05:03 AM
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
0
Vitaly
Top achievements
Rank 1
answered on 09 Oct 2013, 02:37 PM
Thanks so much for your help.
It works.
Tags
General Discussions
Asked by
Vitaly
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Vitaly
Top achievements
Rank 1
Share this question
or