Popup Calendar in edit mode of asp.net gridview

6.5k views Asked by At

All respected, I have a Master detail project asp.net (sql data) project in which Master.aspx along with code behind page Master.aspx.cs. Following is the code:

<asp:TemplateField HeaderText="Date of Failure" SortExpression="Failure_date" >
<EditItemTemplate>
<asp:TextBox ID="EditFailure_date" runat="server"  Text='<%# Bind("Failure_date", "{0:d}") %>' ></asp:TextBox><img src="_images/images.jpg" style="margin-top:3px;width:30px;height:30px;cursor:hand;" onclick="PopupPicker('EditFailure_date')" />  
<asp:RequiredFieldValidator ID="Failure_dateRequiredFieldValidator" runat="server" ControlToValidate="EditFailure_date" Display="Dynamic"  ErrorMessage="Can not be blank" SetFocusOnError="True"></asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top" />
<HeaderStyle HorizontalAlign="Left" VerticalAlign="Top" />
<ItemTemplate>
<asp:Label ID="Failure_date" runat="server"  Text='<%# Bind("Failure_date", "{0:dd/MM/yyyy}") %>'  ></asp:Label>
</ItemTemplate>
</asp:TemplateField>

Now I want to add a popup calender for above text box 'EditFailure_date' without codebehind. Please help.

2

There are 2 answers

1
Josh Mein On BEST ANSWER

You can use the AjaxControlToolkit's calendar like this:

<asp:TextBox ID="EditFailure_date" runat="server"  Text='<%# Bind("Failure_date", "{0:d}") %>' ></asp:TextBox>
<ajaxToolkit:CalendarExtender runat="server" ID="cal_EditFailure_date" TargetControlID="EditFailure_date" /> 

Edit: You can also use a jquery solution such as the jQueryUI DatePicker

0
Code On
 <asp:TextBox ID="txtDOJ" Text='<%# Bind("DOJ", "{0:dd-MMM-yyyy}") %>'                                                                                                runat="server" class="form-control input-sm m-bot15" BackColor="#cbeddc"></asp:TextBox>                                                                                            <asp:CalendarExtender ID="CalExtender" runat="server" Enabled="true" Format="dd-MMM-yyyy"                                                                                       TargetControlID="txtDOJ">                                                                                           </asp:CalendarExtender>