我想在编辑模式下将 gridview 中的默认文本字段更改为 javascript 日期选择器?我该如何编码?
下面的代码(Gridview):
<asp:GridView id="grdViewEmpList" runat="server" AutoGenerateColumns="false" PageSize="5" allowpaging="true" Font-Size="11px" OnRowDataBound="grdViewEmpList_RowDataBound"
GridLines="Both" ShowFooter="false" CssClass="gridview" CellPadding="4" Width="750px" OnRowEditing="grdViewEmpList_RowEditing"
PagerSettings-Mode="Numeric" AllowSorting="true" autopostback="true" ShowHeaderWhenEmpty="True" OnRowCancelingEdit="grdViewEmpList_RowCancelingEdit"
EmptyDataText="No record found" OnRowCreated="grdViewEmpList_RowCreated" OnPageIndexChanging="grdViewEmpList_PageIndexChanging" OnRowUpdating="grdViewEmpList_RowUpdating">
<RowStyle Wrap="true" ForeColor="#666666" BorderColor="#FFFFFF" BorderWidth="0" BackColor="#CCCCFF" CssClass="gridview_alter"/>
<AlternatingRowStyle Wrap="true" ForeColor="#666666" BorderColor="#CCCCCC" BorderWidth="0" BackColor="#FFFFFF" CssClass="gridview_alter"/>
<Columns>
<asp:CommandField ShowEditButton="True" EditText="Edit" UpdateText="Save" ButtonType="Image" ItemStyle-HorizontalAlign="Center" HeaderText="Action" EditImageUrl="~/Images/dotNet/pencil.png" CancelImageUrl="~/Images/dotNet/edit-not-validated-icon.png" UpdateImageUrl="~/Images/dotNet/edit-validated-icon.png"/>
<asp:BoundField DataField="EMP_ID" readonly="true" ItemStyle-Height="20px" HeaderText="Employee ID" HeaderStyle-CssClass="allWidth100" />
<asp:BoundField DataField="NAME" readonly="true" HeaderText="Name" HeaderStyle-CssClass="allWidth460" />
<asp:BoundField DataField="EFF_DATE" HeaderText="Effective Date" HeaderStyle-CssClass="allWidth100" DataFormatString="{0:d}" ItemStyle-HorizontalAlign="Center" ControlStyle-CssClass="txtCommon allWidth80 txtCenter" />
</Columns>
<PagerSettings Mode="Numeric" PageButtonCount="5" Position="Bottom" />
<PagerStyle ForeColor="#FFCC33" HorizontalAlign="left" CssClass="gridview_pager"/>
</asp:GridView>
我想在 EFF_DATE
列中放在 gridview 上方的 HTML 日期选择器代码:
<input type="text" id="txtEffDate" name="txtEffDate" class="txtCommon allWidth80" value="" readonly="readonly" />
<img alt="Calendar" src="../Images/DateTimePickerImg/cal.gif" style="cursor: pointer;" onclick="javascript: NewCssCal('txtEffDate')" />
最佳答案
使用 <asp:TemplateField>
在这种情况下。
BoundField
由数据绑定(bind)控件(例如 GridView)用来将字段的值显示为文本。因此,在使用 TemplateField 时,您也可以出于相同目的使用标签,[即在使用模板定义列的布局时]
因此,更改您的字段的标记: EFF_DATE
来自
<asp:BoundField DataField="EFF_DATE" HeaderText="Effective Date"
HeaderStyle-CssClass="allWidth100" DataFormatString="{0:d}"
ItemStyle-HorizontalAlign="Center"
ControlStyle-CssClass="txtCommon allWidth80 txtCenter" />
为此:
<asp:TemplateField>
<ItemTemplate>
<asp:Label runat="server" ID="lnl1"
Text='<%#DataBinder.Eval(Container.DataItem, "EFF_DATE").ToString()%>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<input type="text" id="txtEffDate" name="txtEffDate"
class="txtCommon allWidth80" value="" readonly="readonly" />
<img alt="Calendar" src="../Images/spain.png" style="cursor: pointer;"
onclick="javascript: NewCssCal('txtEffDate')" />
</EditItemTemplate>
</asp:TemplateField>
关于c# - 如何在编辑模式 ASP .Net 中将日期选择器放入 Gridview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20462286/