gridview日期模板列,使用JS日历My97DatePicker

今天在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()
             }
        } 

    }

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fangqm

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值