今天在GRIDVIEW中用JS日历My97DatePicker
GRIDVIEW建好,并设好数据源,把日期字段设成模板列
方法:只要在GRIDVIEW日期模板列编辑时(在行绑定数据后),在后台CS中对其属性,添加ONCLICK事件WdatePicker();
具体 fangqm.cn.aspx中GRIDVIEW代码,红色为日期列
指定日历JS位置
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
AutoGenerateEditButton="True" CellPadding="4" ForeColor="#333333"
GridLines="None" onrowcancelingedit="GridView1_RowCancelingEdit"
onrowediting="GridView1_RowEditing" onrowupdating="GridView1_RowUpdating"
onrowdatabound="GridView1_RowDataBound">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:TemplateField HeaderText="安装日期">
<EditItemTemplate>
<asp:TextBox ID="txtriqi" runat="server" Text='<%# Bind("anzhuangriqi") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("anzhuangriqi") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="dianwei_name" HeaderText="单位" />
<asp:BoundField DataField="wangdian_name" HeaderText="网点" />
</Columns>
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
fangqm.cn.cs部分代码:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)//数据行绑定
{
if (e.Row.RowType == DataControlRowType.DataRow)//1先判断当前行是不是数据行
{
if ( e.Row.RowState == DataControlRowState.Edit)//2再判断当前行状态是不是处于编辑状态
{
e.Row.Cells[1].Attributes.Add("onclick", "WdatePicker();");//对日期模板列添加单击事件WdatePicker()
}
}
}