田贤追博客 - QQ:260776893,Tel:13065860667

网站建设电子商务博客(网站制作,优化推广,网络营销宣传,B2B,网络广告),网络维护,平面设计及相关的文章信息发布共享。

« 对于ASP.NET 运行环境先装了NET2.0 后装IIS 导致站点无法运行ASPX页面的错误老实人 »

关于NET gridview控件,分页功能设置后不显示的一种情况解决

今天突然发现一个gridview控件设置分页了后,。页面分页不显示,其它都正常,

在VS设置器里也是显示的,

仔细看了一下显示页面,分而功能还是实现了的(显示了当前分页内容),但分页选择显示列却没有。

又仔细的看了一下gridview控件的样式设置。功能设置。都没有问题,

<asp:GridView ID="GridView1" runat="server" Width="100%" AutoGenerateColumns="False"
        CellPadding="4" ForeColor="#333333" GridLines="None" OnRowDataBound="GridView1_RowDataBound">
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <RowStyle BackColor="#EFF3FB" />
        <Columns>
            <asp:BoundField DataField="d记录ID" HeaderText="记录ID">
                <HeaderStyle HorizontalAlign="Left" />
            </asp:BoundField>
              <asp:BoundField DataField="VID" HeaderText="状态">
                <HeaderStyle HorizontalAlign="Left" />
            </asp:BoundField>
            <asp:TemplateField HeaderText="组缸编号">
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("d组缸编号") %>'></asp:Label>
                </ItemTemplate>
                <HeaderStyle HorizontalAlign="Left" />
            </asp:TemplateField>
            <asp:BoundField DataField="d设备编号" HeaderText="设备编号">
                <HeaderStyle HorizontalAlign="Left" />
            </asp:BoundField>
            <asp:BoundField DataField="d色卡" HeaderText="色卡">
                <HeaderStyle HorizontalAlign="Left" />
            </asp:BoundField>
            <asp:BoundField DataField="d色号" HeaderText="色号">
                <HeaderStyle HorizontalAlign="Left" />
            </asp:BoundField>
            <asp:TemplateField HeaderText="数量">
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("d数量") %>'></asp:Label>
                </ItemTemplate>
                <HeaderStyle HorizontalAlign="Left" />
            </asp:TemplateField>
        </Columns>
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#2461BF" />
        <AlternatingRowStyle BackColor="White" />
    </asp:GridView>

  protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.GridView1.PageIndex = e.NewPageIndex;
            gridview1Bind();
        }

 

  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "this.oldcolor=this.style.backgroundColor;this.style.backgroundColor='#dddddd'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.oldcolor;");
                e.Row.Attributes.Add("ondblclick", "window.location='ZGXInfo.aspx?ID=" + e.Row.Cells[0].Text + "';");
            }
            e.Row.Cells[0].Style.Add("display", "none");
        }


        private void gridview1Bind()
        {
            if (this.ddl_cjSelect.Items.Count < 1)
            {
                return;
            }
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("select top 20 TBDye.VID,TBDye.ID as d记录ID,TBDye.Code as d组缸编号,TBMachine.Code as d设备编号,TBColorCard.Name as d色卡,TBColorNO.Code as d色号,TBDye.Num as d数量");
            sb.Append(" from TBDye,TBDyeLine,TBColorCard,TBColorNO,TBMachine,TBWorkOrder,TBOrder");
            sb.Append(" where TBDye.ID=TBDyeLine.TBDyeID");
            sb.Append(" and TBWorkOrder.ID=TBDyeLine.TBWorkOrderID");
            sb.Append(" and TBWorkOrder.TBOrderID=TBOrder.ID");
            sb.Append(" and TBColorNO.ID=TBDye.TBColorNOID");
            sb.Append(" and TBColorNO.TBColorCardID=TBColorCard.ID");
            sb.Append(" and TBDye.TBMachineID=TBMachine.ID");
            sb.Append(" and TBDye.User5='" + this.ddl_cjSelect.SelectedValue + "'");
            string keyvalue = this.tb_key.Text.Trim();
            if (keyvalue != "")
            {
                string[] keyarr = keyvalue.Split(' ');
                foreach (string keytxt in keyarr)
                {
                    sb.Append(" and (charindex('" + keytxt + "',TBColorCard.Name)>0 or charindex('" + keytxt + "',TBColorNO.Code)>0 or charindex('" + keytxt + "',TBOrder.Code)>0)");
                }
            }
            if (this.ddl_VID.SelectedValue != "")
            {
                sb.Append(" and TBDye.VID='" + this.ddl_VID.SelectedValue + "'");
            }
            sb.Append(" group by TBDye.VID,TBDye.ID,TBMachine.Code,TBColorCard.Name,TBColorNO.Code,TBDye.Num,TBDye.Code");

            sb.Append(" order by TBDye.ID desc");

            //Response.Write(sb.ToString());
            //Response.End();

            System.Data.DataTable dt = new TianSoft.Dal.SqlExcute().ExecuteDataTable(sb.ToString());
            this.GridView1.DataSource = dt;
            this.GridView1.DataKeyNames = new string[] { "d记录ID" };
            this.GridView1.DataBind();
            dt.Dispose();
        }

 

在网上找了一会。也没找到解决办法,有说的NET的BUG(大姨妈)样式删除重设就好。也有其它的一些方法,

测试后都没解决。

最后只有一步步的测试代码

结果发现 问题出现在

  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "this.oldcolor=this.style.backgroundColor;this.style.backgroundColor='#dddddd'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.oldcolor;");
                e.Row.Attributes.Add("ondblclick", "window.location='ZGXInfo.aspx?ID=" + e.Row.Cells[0].Text + "';");
            }
            e.Row.Cells[0].Style.Add("display", "none");
        }

这个上,

里面有一句

   e.Row.Cells[0].Style.Add("display", "none");
设置有问题,

对于gridview来说,分页的列默认为第一列,所以被这条语句给隐掉了,

但有时候我们有必要对某一列隐掉,

其实把这里的代码改一下就OK了

  if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "this.oldcolor=this.style.backgroundColor;this.style.backgroundColor='#dddddd'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.oldcolor;");
                e.Row.Attributes.Add("ondblclick", "window.location='ZGXInfo.aspx?ID=" + e.Row.Cells[0].Text + "';");
                e.Row.Cells[0].Style.Add("display", "none");
            }
            if (e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[0].Style.Add("display", "none");
            }

这样分页就显示出来了。

具体解析就没有了。应该看得明白。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

日历

最新评论及回复

最近发表

Powered By Z-Blog 1.8 Walle Build 91204

© 2007-2009 Powered By 田贤追博客 All rights reserved. 浙ICP备09005319号·