Automatically post current date in gridview Editmode ASP.NET C#
Is there a way were I could set the current date in one of the field while in edit mode in gridview? What I want to do is when a user click on a boolean property (true or false check box field) in gridview it will automatically set the current date in the 'datereturned' field.
Here's a sample of my code in gridview.
<asp:GridView ID="GridView2" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="lenid,bookid, booktitle, EmployeeID"
DataSourceID="currentborrowersDataSource">
<Columns>
<asp:CommandField HeaderStyle-Width="140px" ButtonType="Button" ShowDeleteButton="False" ShowEditButton="True" />
<asp:BoundField DataField="lenid" HeaderText="lenid" InsertVisible="False"
ReadOnly="True" Visible="false" SortExpression="lenid" />
<asp:BoundField DataField="bookid" HeaderText="bookid"
ReadOnly="True" Visible="false" SortExpression="bookid" />
<asp:BoundField DataField="booktitle" HeaderText="Book Title"
ReadOnly="true" SortExpression="booktitle" />
<asp:BoundField DataFiel开发者_开发技巧d="EmployeeID" HeaderText="Employee ID"
ReadOnly="true" SortExpression="EmployeeID" />
<asp:BoundField DataField="department" HeaderText="Department"
ReadOnly="true" SortExpression="department" />
<asp:BoundField DataField="dateborrowed" HeaderText="Date borrowed"
SortExpression="dateborrowed" />
<asp:BoundField DataField="datereturned" HeaderText="Date returned"
SortExpression="datereturned" />
<asp:CheckBoxField DataField="returned" HeaderText="Returned" SortExpression="flag" />
</Columns>
</asp:GridView>
Any help would be much appreciated. Thanks in advance!!
You need to convert it to template control and put the TextBox
control in it like:..
<asp:TemplateField>
<asp:TextBox runat="server" ID="textbox1" Text='<%# DateTime.Now.ToString() %>'>
</asp:TextBox>
</asp:TemplateField>
You would have to handle the preRender
event of GridView
and loop over the rows and add the date in the textbox
manually for each row...
精彩评论