How to get clientId of web control under grid view in editItemTemplate

Hello all,
I am using Master page concept and this is content page.
I want to get How to get clientId of web control under grid view in editItemTemplate.
This is my code:


 <asp:GridView ID="gvSoftwareMaster" runat="server" CellSpacing="1" Width="100&#37;" AutoGenerateColumns="False"
                    CssClass="gridBackColor" BorderWidth="0px" HorizontalAlign="Center" OnRowEditing="gvSoftwareMaster_RowEditing" OnRowUpdating="gvSoftwareMaster_RowUpdating" OnRowDataBound="gvSoftwareMaster_RowDataBound">
                    <HeaderStyle CssClass="colHeading"></HeaderStyle>
                    <RowStyle CssClass="altRow1"></RowStyle>
                    <AlternatingRowStyle CssClass="altRow2"></AlternatingRowStyle>
                    <Columns>
                        <asp:TemplateField HeaderText="Vendor Name">
                        <ItemTemplate>
                            <asp:Label ID="lblVendor" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"VendorName") %>'></asp:Label>
                            <input type="hidden" id="chkVendorId" name="chkVendorId[]" value='<%# DataBinder.Eval(Container.DataItem,"VendorID")%>' runat="server" />
                        </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Software Name">
                         <ItemTemplate>
                                <a href="javascript:void(0);" onclick="javascript:return mfSystemPage('<%# DataBinder.Eval(Container.DataItem,"ProductID") %>');"> <asp:Label ID="lblSoftware" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"ProductName") %>'></asp:Label></a>
                                <input type="hidden" id="chkProductId" name="chkProductId[]" value='<%# DataBinder.Eval(Container.DataItem,"ProductID")%>' runat="server" />
                        </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Version">
                         <ItemTemplate>
                        <asp:Label ID="lblVersion" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"ProductVersion") %>'></asp:Label>
                        </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Account Name">
                         <ItemTemplate>
                        <asp:Label ID="lblAccountName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"COST_CENTER_NAME") %>'></asp:Label>
                        </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Licensed Software">
                         <ItemTemplate>
                        <asp:Label ID="lbllicense" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"License") %>'></asp:Label>
                        </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Licensed Size">
                         <ItemTemplate>
                        <asp:Label ID="lbllicensesize" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"LicenseSize") %>'></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                        <asp:TextBox ID="txtlicensesize" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"LicenseSize") %>'></asp:TextBox>
                        </EditItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Licensed Start Date">
                         <ItemTemplate>
                            <asp:Label ID="lblstartDate" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"StartDate") %>'></asp:Label>

                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="txtstartDate" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"StartDate") %>'></asp:TextBox>
                            <a href="javascript:show_calendar('<%=txtstartDate.ClientID%>');"><img height="20"
                                    src="./Include/images/calendar2.gif" width="15" align="top" border="0"></a>
                        </EditItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Licensed End Date">
                         <ItemTemplate>
                            <asp:Label ID="lblEndDate" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"EndDate") %>'></asp:Label>

                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="txtEndDate" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"EndDate") %>'></asp:TextBox>
                            <a href="javascript:show_calendar('<%=txtEndDate.ClientID%>');"><img height="20"
                                    src="./Include/images/calendar2.gif" width="15" align="top" border="0"></a>
                        </EditItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Document">
                         <ItemTemplate>
                             <asp:Label ID="lblDocument" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"FileDocument") %>'></asp:Label>
                        </ItemTemplate>
                        </asp:TemplateField>
                        <asp:CommandField ShowEditButton="true" />
                    </Columns>
                </asp:GridView>

At the time of compiling, It gives an 2 error.
The error is as follows:


[B]The name 'txtstartDate' does not exist in the current context[/B]	C:\\Inetpub\\wwwroot\\LicenseSoftware\\UI\\LicenseSoftware\\softwareMaster.aspx	366	
[B]The name 'txtEndDate' does not exist in the current context[/B]	C:\\Inetpub\\wwwroot\\LicenseSoftware\\UI\\LicenseSoftware\\softwareMaster.aspx	377	


Please Help me.

The only time you can access the clientid of an item in a template is in the itemdatabound event as far as I know. Are you looking for the clientid so you can access it through script? If so I personally would prefer to use unobtrusive javascript and give my controls class values that I can search for.

The only time you can access the clientid of an item in a template is in the itemdatabound event as far as I know

Not quite–there are alot of ways to skin that cat. The key thing to remember is that your template controls exist on a per-row basis, so you need to call FindControl() from the correct NamingContainer. I really can’t advise much more because I am still unclear on what you are actually doing here–why do you need the ClientID and what are you using it for?

Yeah forgot you can also drill right in through the gridview:-

gridview1.Rows(x).FindControl(“mycontrol”)

I am looking a client ID beacuse i want to pass it to a Javascript calender Function which will return the clickable date to that textbox ID .

Any Way i have solved it…

and i am posting it how i am solved it…
Javascript Code


 function mfCalender(parametrId,position)
    {
    var tblobj=document.getElementById("<&#37;=gvSoftwareMaster.ClientID%>");
    var strClientId="";
     for(var i=1;i<tblobj.rows.length;i++)
          {
            if(tblobj.rows[i].cells[position] && tblobj.rows[i].cells[position].childNodes[0] && tblobj.rows[i].cells[position].childNodes[0].nodeName == 'INPUT' && tblobj.rows[i].cells[position].childNodes[0].type == 'text')
                {
                strClientId=tblobj.rows[i].cells[position].childNodes[0].id;
                   if(strClientId.indexOf(parametrId)>0)
                    {
                    show_calendar(strClientId);
                    }
                }
           }

    }

Aspx Grid View Code


<asp:GridView ID="gvSoftwareMaster" runat="server" CellSpacing="1" Width="100%" AutoGenerateColumns="False"
                    CssClass="gridBackColor" BorderWidth="0px" HorizontalAlign="Center" OnRowEditing="gvSoftwareMaster_RowEditing" OnRowUpdating="gvSoftwareMaster_RowUpdating" OnRowDataBound="gvSoftwareMaster_RowDataBound" OnRowCancelingEdit="gvSoftwareMaster_RowCancelingEdit" >
                    <HeaderStyle CssClass="colHeading"></HeaderStyle>
                    <RowStyle CssClass="altRow1"></RowStyle>
                    <AlternatingRowStyle CssClass="altRow2"></AlternatingRowStyle>
                    <Columns>
                        <asp:TemplateField HeaderText="Vendor Name">
                        <ItemTemplate>
                            <asp:Label ID="lblVendor" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"VendorName") %>'></asp:Label>
                            <input type="hidden" id="chkVendorId" name="chkVendorId[]" value='<%# DataBinder.Eval(Container.DataItem,"VendorID")%>' runat="server" />
                        </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Software Name">
                         <ItemTemplate>
                                <a href="javascript:void(0);" onclick="javascript:return mfSystemPage('<%# DataBinder.Eval(Container.DataItem,"ProductID") %>');"> <asp:Label ID="lblSoftware" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"ProductName") %>'></asp:Label></a>
                                <input type="hidden" id="chkProductId" name="chkProductId[]" value='<%# DataBinder.Eval(Container.DataItem,"ProductID")%>' runat="server" />
                        </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Version">
                         <ItemTemplate>
                        <asp:Label ID="lblVersion" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"ProductVersion") %>'></asp:Label>
                        </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Account Name">
                         <ItemTemplate>
                        <asp:Label ID="lblAccountName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"COST_CENTER_NAME") %>'></asp:Label>
                        </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Licensed Software">
                         <ItemTemplate>
                        <asp:Label ID="lbllicense" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"License") %>'></asp:Label>
                        </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Licensed Size">
                         <ItemTemplate>
                        <asp:Label ID="lbllicensesize" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"LicenseSize") %>'></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                        <asp:TextBox ID="txtlicensesize" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"LicenseSize") %>'></asp:TextBox>
                        </EditItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Licensed Start Date">
                         <ItemTemplate>
                            <asp:Label ID="lblstartDate" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"StartDate") %>'></asp:Label>
                         </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="txtstartDate" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"StartDate") %>'></asp:TextBox>
                            <a ID="aCalendar1" runat=server href="javascript:mfCalender('txtstartDate','6');"><img height="20" src="./Include/images/calendar2.gif" width="15" align="top" border="0"></a>
                         </EditItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Licensed End Date">
                         <ItemTemplate>
                            <asp:Label ID="lblEndDate" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"EndDate") %>'></asp:Label>
                         </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="txtEndDate" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"EndDate") %>'></asp:TextBox>
                            <a ID="aCalendar2" runat=server href="javascript:mfCalender('txtEndDate','7');"><img height="20" src="./Include/images/calendar2.gif" width="15" align="top" border="0"></a>
                         </EditItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Document">
                         <ItemTemplate>
                             <asp:Label ID="lblDocument" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"FileDocument") %>'></asp:Label>
                        </ItemTemplate>
                        </asp:TemplateField>
                        <asp:CommandField ShowEditButton="true" />
                    </Columns>
                </asp:GridView>

The problem is solved. I asked another function and from that i call it calender function.