今天突然发现一个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");
}
这样分页就显示出来了。
具体解析就没有了。应该看得明白。