ASP.net GridView列表表头不显示,问题不知道出在哪了

DifferentSeasons_Y 发布于 2017/08/07 17:40
阅读 268
收藏 0

跪拜各位大神,我真不知道我错哪了,我现在列表的表头那一行不显示,请问是为什么。

aspx页面代码:

<asp:GridView ID="grvLog" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" onrowdatabound="grvLog_RowDataBound" PageSize="200" Width="100%" AllowPaging="True" ShowHeader="False">
	<PagerSettings Visible="False" />
	<Columns>
		<asp:CommandField HeaderText="序号">
			<HeaderStyle BackColor="#E9E9ED" Font-Names="微软雅黑" ForeColor="Black" Height="30px" />
			<ItemStyle Width="60px" HorizontalAlign="Center" />
		</asp:CommandField>
		<asp:BoundField DataField="rz_yhid" HeaderText="用户ID" SortExpression="rz_yhid">
			<HeaderStyle BackColor="#E9E9ED" Font-Names="微软雅黑" ForeColor="Black" />
			<ItemStyle Width="50px" HorizontalAlign="Center" />
		</asp:BoundField>
		<asp:BoundField DataField="rz_yhm" HeaderText="用户名" SortExpression="rz_yhm">
			<HeaderStyle BackColor="#E9E9ED" Font-Names="微软雅黑" ForeColor="Black" />
			<ItemStyle Width="80px" HorizontalAlign="Center" />
		</asp:BoundField>
		<asp:BoundField DataField="rz_ip" HeaderText="登录IP" SortExpression="rz_ip">
			<HeaderStyle BackColor="#E9E9ED" Font-Names="微软雅黑" ForeColor="Black" />
			<ItemStyle Width="120px" HorizontalAlign="Center" />
		</asp:BoundField>
		<asp:BoundField DataField="rz_pc" HeaderText="登录计算机名" SortExpression="rz_pc">
			<HeaderStyle BackColor="#E9E9ED" Font-Names="微软雅黑" ForeColor="Black" />
			<ItemStyle HorizontalAlign="Center" Width="180px" />
		</asp:BoundField>
		<asp:BoundField DataField="rz_sj" HeaderText="操作时间" SortExpression="rz_sj">
			<HeaderStyle BackColor="#E9E9ED" Font-Names="微软雅黑" ForeColor="Black" />
			<ItemStyle Width="150px" HorizontalAlign="Center" />
		</asp:BoundField>
		<asp:BoundField DataField="rz_gn" HeaderText="页面" SortExpression="rz_gn">
			<HeaderStyle BackColor="#E9E9ED" Font-Names="微软雅黑" ForeColor="Black" />
			<ItemStyle Width="150px" HorizontalAlign="Center" />
		</asp:BoundField>
		<asp:BoundField DataField="rz_cz" HeaderText="操作" SortExpression="rz_cz">
			<HeaderStyle BackColor="#E9E9ED" Font-Names="微软雅黑" ForeColor="Black" />
			<ItemStyle Width="150px" HorizontalAlign="Center" />
		</asp:BoundField>
		<asp:BoundField DataField="rz_nr" HeaderText="内容" SortExpression="rz_nr">
			<HeaderStyle BackColor="#E9E9ED" Font-Names="微软雅黑" ForeColor="Black" />
			<ItemStyle HorizontalAlign="Center" />
		</asp:BoundField>
		<asp:BoundField DataField="rz_jg" HeaderText="操作结果" SortExpression="rz_jg">
			<HeaderStyle BackColor="#E9E9ED" Font-Names="微软雅黑" ForeColor="Black" />
			<ItemStyle Width="80px" HorizontalAlign="Center" />
		</asp:BoundField>
	</Columns>
	<EmptyDataTemplate>
		<table style="width:100%;">
			<tr class="style167">
				<td>
					序号</td>
				<td>
					用户ID</td>
				<td>
					用户名</td>
				<td>
					登录IP</td>
				<td>
					登录计算机名</td>
				<td>
					操作时间</td>
				<td>
					页面</td>
				<td>
					操作</td>
				<td>
					内容1</td>
				<td>
					内容2</td>
				<td>
					内容3</td>
				<td>
					操作结果</td>
			</tr>
			<tr>
				<td class="style166" colspan="12">
					没有符合条件的记录!</td>
			</tr>
		</table>
	</EmptyDataTemplate>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString_Material %>" SelectCommand="SELECT rz_id, rz_yhid, rz_yhm, rz_ip, rz_pc, rz_sj, rz_gn, rz_cz, rz_nr,rz_jg FROM gy_rz WHERE (DATEDIFF(day, rz_sj, GETDATE()) &lt;= @rz_sj) ORDER BY rz_id">
	<SelectParameters>
		<asp:ControlParameter ControlID="drpRq" Name="rz_sj" PropertyName="SelectedValue" />
	</SelectParameters>
</asp:SqlDataSource>

aspx.cs页面代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.IO;

public partial class System_sysLog : System.Web.UI.Page
{
    protected void set_page()
    {
        drpYm.Items.Clear();

        if (grvLog.PageCount > 0)
        {
            for (int i = 1; i <= grvLog.PageCount; i++)
            {
                drpYm.Items.Add(i.ToString() + "/" + grvLog.PageCount);
            }
            drpYm.Text = Convert.ToString(grvLog.PageIndex + 1) + "/" + grvLog.PageCount;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {
                if (Session["UserID"] == null)
                {
                    Response.Redirect("../login.aspx");
                }
                grvLog.DataBind();
                set_page();
                btn1_Click(null, null);
            }
        }
        catch
        {
            ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>alert('系统错误_Load(')</script>");
        }
    }

    protected void grvLog_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        try
        {
            if (e.Row.RowIndex != -1)
            {
                int id = e.Row.RowIndex + 1;
                e.Row.Cells[0].Text = id.ToString();
            }

            int i;
            for (i = -1; i < grvLog.Rows.Count; i++)
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");
                    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
                }
            }

            labCount.Text = grvLog.Rows.Count.ToString();
        }
        catch
        {
            ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>alert('系统错误 grvLog_RowDataBound')</script>");
        }
    }
    protected void drpRq_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            grvLog.DataBind();
            set_page();
            btn1_Click(null, null);
        }
        catch
        {
            ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>alert('系统错误 drpRq_SelectedIndexChanged')</script>");
        }
    }
    protected void btn1_Click(object sender, EventArgs e)
    {
        try
        {
            if (grvLog.PageCount > 0)
            {
                grvLog.PageIndex = 0;
                set_page();
            }
        }
        catch
        {
            ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>alert('系统错误! btn1_Click')</script>");
        }
    }
    protected void btn3_Click(object sender, EventArgs e)
    {
        try
        {
            if (grvLog.PageIndex > 0)
            {
                grvLog.PageIndex -= 1;
                set_page();
            }
        }
        catch
        {
            ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>alert('系统错误! btn3_Click')</script>");
        }
    }
    protected void btn2_Click(object sender, EventArgs e)
    {
        try
        {
            if (grvLog.PageCount > 0)
            {
                if (grvLog.PageIndex < grvLog.PageCount - 1)
                {
                    grvLog.PageIndex += 1;
                    set_page();
                }
            }
        }
        catch
        {
            ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>alert('系统错误! btn2_Click')</script>");
        }
    }
    protected void btn4_Click(object sender, EventArgs e)
    {
        try
        {
            if (grvLog.PageCount > 0)
            {
                grvLog.PageIndex = grvLog.PageCount - 1;
                set_page();
            }
        }
        catch
        {
            ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>alert('系统错误! btn4_Click')</script>");
        }
    }
    protected void drpYm_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            grvLog.PageIndex = Convert.ToInt32(drpYm.Text.Substring(0, drpYm.Text.IndexOf("/"))) - 1;
        }
        catch
        {
            ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>alert('系统错误! drpYm_SelectedIndexChanged')</script>");
        }
    }
}

 

加载中
0
天体图
天体图

ShowHeader="false",这个去掉,不知道在哪的话,请搜一下你的代码

DifferentSeasons_Y
DifferentSeasons_Y
请收下我的膝盖,大神,我找了好长时间,一直没有注意到这个属性!!!
返回顶部
顶部