jquery datepicker date not binding to asp.net textbox in gridview editing/updating (with masterpage)
in the code below, the string sFoodFormReceived1 always gets the value of DateTime.Now. I dont know how to make the date clicked on the datepicker UI bind to the textbox in the gridview gvReservationsWithForms.
protected void gvReservationsWithForms_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = gvReservationsWithForms.Rows[e.RowIndex];
string sFoodFormReceived1 = ((TextBox)(row.Cells[9].Controls[1])).Text;
DataTable dt = dsReservationsToBind.Tables[0];
dt.Rows[gvReservationsWithForms.EditIndex]["FoodFormReceived"] = new DateTime(System.DateTime.Parse(sFoodFormReceived1));
DataRow dr = dt.Rows[row.DataItemIndex];
var Reservation = new reservation_RoomReservationTableAdapter();
Reservation.Update(dr);
gvReservationsWithForms.EditIndex = -1;
gvReservationsWithForms.DataBind();
}
<asp:Content ID="Content4" ContentPlaceHolderID="Main" Runat="Server">
<script type="text/javascript">
$(document).ready(function ()
{$("input[id$='tbFoodFormReceivedEditItemTemplate']").datepicker();})
</script>
<asp:Gri开发者_Python百科dView ID="gvReservationsWithForms" runat="server"
AutoGenerateColumns="False"
DataKeyNames="RoomReservationID" AutoGenerateSelectButton="True"
allowsorting ="True" AutoGenerateEditButton="True" BackColor="White"
BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3"
GridLines="Vertical" onsorting="gvReservationsWithForms_Sorting1"
onrowcancelingedit="gvReservationsWithForms_RowCancelingEdit"
onrowediting="gvReservationsWithForms_RowEditing"
onrowupdating="gvReservationsWithForms_RowUpdating"
onselectedindexchanged="gvReservationsWithForms_SelectedIndexChanged1"
onrowupdated="gvReservationsWithForms_RowUpdated">
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<columns>
<asp:BoundField DataField="RoomReservationID" HeaderText="Confirmation ID" SortExpression="RoomReservationID" Visible="false" />
<asp:BoundField DataField="Room" HeaderText="Room" SortExpression="Room" ReadOnly="true"/>
<asp:BoundField DataField="BeginDate" HeaderText="Event Begin Date" SortExpression="BeginDate" ReadOnly="true"/>
<asp:BoundField DataField="EndDate" HeaderText="Event End Date" SortExpression="EndDate" ReadOnly="true"/>
<asp:BoundField DataField="BeginTime" HeaderText="Event Begin Time" SortExpression="BeginTime" ReadOnly="true"/>
<asp:BoundField DataField="EndTime" HeaderText="Event End Time" SortExpression="EndTime" ReadOnly="true"/>
<asp:BoundField DataField="Department" HeaderText="Department/Organization" SortExpression="Department" ReadOnly="true"/>
<asp:BoundField DataField="Activity" HeaderText="Activity" SortExpression="Activity" ReadOnly="true"/>
<asp:TemplateField HeaderText="Food Form Received"
SortExpression="FoodFormReceived">
<EditItemTemplate>
<asp:TextBox ID="tbFoodFormReceivedEditItemTemplate" runat="server" CssClass="datepickers"
Text='<%# DateTime.Now%>'> </asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("FoodFormReceived") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</columns>
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#DCDCDC" />
</asp:GridView>
</asp:Content>
You may want to instead set the textbox to datetime.now in code, on RowEditing instead. That way, the binding doesn't interfere. It could be that...
also, you may get better performance if you do:
$("#<%= gvReservationsWithForms.ClientID %>")
.find("input[id$='tbFoodFormReceivedEditItemTemplate']").datepicker();
Instead, so you restrict the input controls to just the gridview, and not the entire page.
精彩评论