在网格视图中处于编辑模式时,我是否可以在其中一个字段中设置当前日期?我想要做的是当用户点击gridview中的布尔属性(true或false复选框字段)时,它将自动在'datereturned'字段中设置当前日期。
以下是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 DataField="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>
非常感谢任何帮助。在此先感谢!!
答案 0 :(得分:1)
您需要将其转换为模板控件并将TextBox
控件放在其中,如:..
<asp:TemplateField>
<asp:TextBox runat="server" ID="textbox1" Text='<%# DateTime.Now.ToString() %>'>
</asp:TextBox>
</asp:TemplateField>
答案 1 :(得分:0)
您必须处理preRender
GridView
事件并循环遍历行,并为每行手动添加textbox
日期...