0

I am adding datepicker in girdview in visual web part project.Below is the HTML code.When i build the project I am getting error as 'txtImpactedEndTime' does not exist in current context. Please suggest.

<asp:TemplateField HeaderText="End Time" HeaderStyle-ForeColor="#357328" HeaderStyle-Font-Bold="false">
                            <ItemTemplate>
                                <asp:TextBox ID="txtImpactedEndTime" runat="server" Text='<%# Eval("Col4") %>'></asp:TextBox>
                                <a href="javascript:NewCssCal('<%= txtImpactedEndTime.ClientID %>','DDMMMYYYY','arrow',true,'24');">
                                <img id="ImgImpactedEndTime" src="https://gdpdev.accenture.com/Shared%20Documents/cal.gif" runat="server" style="padding-right: 7px; padding-left: 0px; border: none; vertical-align: middle; padding-bottom: 5px; padding-top: 1px; background-repeat: no-repeat;" /></a> 
                                <%--<SharePoint:DateTimeControl ID="dtcImpactedEndTime" runat="server"  SelectedDate='<%# Eval("Col4") %>'  />--%>
                            </ItemTemplate>
                            <ItemStyle Width="15%" />
                        </asp:TemplateField>
Sumit
  • 3
  • 4
  • I think the javascript is the problem. Its trying to find the control in a Gridview, but cant find it as its nested. This may help http://stackoverflow.com/questions/10625948/how-to-find-textbox-in-gridview-using-javascript-function-fired-on-onclientside – Computer May 12 '16 at 15:45
  • I also tried by using javascript, But the resukt is same.. and script patr is : – Sumit May 13 '16 at 10:50

1 Answers1

0

If you are getting that error on build, it means you are trying to call txtImpactedEndTime on codebehind, which is impossible because it's an item inside the gridview, not a part of your interface yet.

You should use "FindControl" to reach items inside the rows:

TextBox txtImpactedEndTime = (TextBox)GridView1.FindControl("txtImpactedEndTime");
Pecheneg
  • 768
  • 3
  • 11
  • 27
  • I also tried by using javascript, But the resukt is same.. and script patr is : – Sumit May 13 '16 at 10:49