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>

 

 

你可能感兴趣的:(server,object,asp,div,button)