GridView 操作事件绑定技巧,单元格属性绑定指定值

 

1/在绑定数据时,绑定指定事件 
2/单元格控件绑定一个或者多个,指定值
3/GridView的分页属性,

 protected void gv_BomList_RowDataBound(object sender, GridViewRowEventArgs e)
    {      
        if (e.Row.RowType == DataControlRowType.DataRow)
        {   
            for (int i = 1; i < e.Row.Cells.Count; i++)
            {
                e.Row.Cells[i].Attributes.Add("onclick", ClientScript.GetPostBackClientHyperlink(e.Row.Cells[0].FindControl("SelectButton"), ""));
            }
            e.Row.Cells[0].Attributes.Add("onclick", ClientScript.GetPostBackClientHyperlink(e.Row.Cells[0].FindControl("chk_Button"), ""));
           
            ((LinkButton)e.Row.FindControl("SelectButton")).CommandArgument = e.Row.RowIndex.ToString();
            ((LinkButton)e.Row.FindControl("chk_Button")).CommandArgument = e.Row.RowIndex.ToString();
            e.Row.Attributes.Add("onmouseover", "oldBG=this.style.backgroundColor; this.style.backgroundColor='#E6F5FA';");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=oldBG");
        }
    }

 <asp:TemplateField Visible="False" HeaderText="Select">
                                    <ItemTemplate>
                                        <asp:LinkButton ID="SelectButton" runat="server" CausesValidation="False" CommandName="Button"
                                            thisEcnID='<%#Eval("EcnDKey") %>' thisBomID='<%#Eval("MaterialBomKey") %>' Text="选择"></asp:LinkButton></ItemTemplate>
                                </asp:TemplateField>

//----------------------------------------------------------------------------------------------------------------------------------------------------------

  <PagerTemplate>
                                <div style="text-align: center">
                                    <asp:Label ID="lbl_count" runat="server" Text='<%# "总记录数:"+((System.Data.DataTable)((GridView)Container.NamingContainer).DataSource).Rows.Count+ "  "%>'></asp:Label>
                                    <asp:Label ID="lbl_page_size3" runat="server" Text='<%# "每页"+gv_BomList.PageSize+"条" %>'></asp:Label>
                                    <asp:Label ID="lblPage1" runat="server" Text='<%# "第" + (((GridView)Container.NamingContainer).PageIndex + 1)  + "页/共" + (((GridView)Container.NamingContainer).PageCount) + "页" %> '></asp:Label>
                                    <asp:LinkButton ID="lbnFirst1" runat="Server" CommandArgument="First" CommandName="Page"
                                        Enabled="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>" Text="首页"></asp:LinkButton>
                                    <asp:LinkButton ID="lbnPrev1" runat="server" CommandArgument="Prev" CommandName="Page"
                                        Enabled="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>" Text="上一页"></asp:LinkButton>
                                    <asp:LinkButton ID="lbnNext1" runat="Server" CommandArgument="Next" CommandName="Page"
                                        Enabled="<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>"
                                        Text="下一页"></asp:LinkButton>
                                    <asp:LinkButton ID="lbnLast1" runat="Server" CommandArgument="Last" CommandName="Page"
                                        Enabled="<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>"
                                        Text="尾页"></asp:LinkButton>
                                </div>
                            </PagerTemplate>

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

那小x的传说

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

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

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

打赏作者

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

抵扣说明:

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

余额充值