Gridview日历扩展程序获取日期
本文关键字:获取 取日期 程序 扩展 日历 Gridview | 更新日期: 2023-09-27 18:16:22
我有一个GridView,它允许用户使用EmptyDataTemplate输入数据。有一个具有日历扩展程序的文本框。我想获得输入的日期(格式MM/dd/yyyy),并将其传递到数据库。
请告诉我怎么做。
我代码:<asp:GridView ID="GV_Rotl_Asgt" runat="server" EnableModelValidation="True"
BackColor="White" BorderColor="#999999" BorderStyle="None"
BorderWidth="1px" CellPadding="3" Font-Names="Arial"
Font-Size="8pt" GridLines="Vertical"
AllowSorting="True" EnableSortingAndPagingCallbacks="True" AutoGenerateColumns="False"
Width="1196px"
ShowFooter="True" OnRowCommand="GV_RowCommand" DataKeyNames="Emplid">
<FooterStyle BackColor="#CCCCCCC" ForeColor="Black" />
<PagerSettings PageButtonCount="1000" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<Columns>
<asp:TemplateField HeaderText="Action" HeaderStyle-ForeColor="#00349C">
<ItemTemplate>
<asp:LinkButton ID="btnEdit" Text="Edit" runat="server" CommandName="Edit" CssClass="infotitle" /> <br />
<asp:LinkButton ID="btnDelete" Text="Delete" runat="server" CommandName="Delete" CssClass="infotitle"/>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="btnUpdate" Text="Update" runat="server" CommandName="Update" CssClass="infotitle" />
<asp:LinkButton ID="btnCancel" Text="Cancel" runat="server" CommandName="Cancel" CssClass="infotitle"/>
</EditItemTemplate>
<FooterTemplate>
<asp:LinkButton runat="server" ID="Insert" Text="Insert" CommandName="InsertNew" CssClass="infotitle" />
<asp:LinkButton runat="server" ID="Cancel" Text="Cancel" CommandName="CancelNew" CssClass="infotitle" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<table id="NoDatatbl" width="100%" style="margin-right: 0px">
<tr>
<td class="ColumnHead" width="150px">
To Date</td>
<td class="ColumnHead" width="150px">
From Date</td>
<td class="ColumnHead" width="150px">
Rotational Assignment</td>
<td class="ColumnHead" width="150px">
Location</td>
<td class="ColumnHead" width="150px">
</td>
</tr>
</table>
<table id="NoDatatbl1" width="100%" style="margin-right: 0px">
<tr>
<td class="ColumnHead" width="150px">
<asp:TextBox runat="server" ID="NodataToDt" format="MM/dd/yyyy"/>
<asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="NodataToDt" format="MM/dd/yyyy"/>
</td>
<td class="ColumnHead" width="150px">
<asp:TextBox runat="server" ID="NodatafrmDt" format="MM/dd/yyyy"/>
<asp:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="NodatafrmDt" format="MM/dd/yyyy"/>
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="NodatafrmDt" ControlToCompare="NodataToDt" Operator="GreaterThanEqual"
Display="Dynamic" ErrorMessage="From Date should be greater than To Date"
Type="Date"></asp:CompareValidator>
<asp:ValidatorCalloutExtender ID="CompareValidator1_ValidatorCalloutExtender" runat="server" Enabled="True" TargetControlID="CompareValidator1">
</asp:ValidatorCalloutExtender>
</td>
<td class="ColumnHead" width="150px">
<asp:TextBox runat="server" ID="NodataRotl" /></td>
<td class="ColumnHead" width="150px">
<asp:TextBox runat="server" ID="NodataLoc" /></td>
<td class="ColumnHead" width="150px">
<asp:LinkButton runat="server" ID="LinkButton1" Text="Insert" CommandName="NoDataInsert" CssClass="infotitle" />
</td>
</tr>
</table>
</EmptyDataTemplate>
</asp:GridView>
基本上,我想从NodataToDt &NodatafrmDt文本框,并将值传递给我的存储过程。
谢谢
在你的代码后面:
// Find the 2 text boxes within your GridView control
TextBox toDateTextBox = (TextBox)GV_Rotl_Asgt.FindControl("NodataToDt");
TextBox fromDateTextBox = (TextBox)GV_Rotl_Asgt.FindControl("NodatafrmDt");
// Grab the values out of those text boxes
string toDate = toDateTextBox.Text;
string fromDate = fromDateTextBox.Text;
从这里,您可以对这两个字符串值做任何您需要的事情。