public partial class luntan : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
getdate();
}
} protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string ftID = GridView1.DataKeys[e.RowIndex].Value.ToString();
Response.Redirect("~/luntanlook.aspx?ftID=" + ftID);
}
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[0].Visible = false;
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{ if (Session["userid"] == null)
{
Response.Write("<script>alert('请先登录!');location.href='luntan.aspx';</script>");
}
else
{
Response.Redirect("~/AddNewT.aspx");
}
}
protected void getdate()
{
DataSet ds = DB.reDs("select ftID,ftuserID,ftTitle,ftContent,ftDate,userName from FT,Users where FT.ftuserID=Users.userID order by ftDate desc");
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//高亮显示指定行
e.Row.Attributes.Add("onMouseOver", "Color=this.style.backgroundColor;this.style.backgroundColor='#FFF000'");
e.Row.Attributes.Add("onMouseOut", "this.style.backgroundColor=Color;");
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
getdate();
}
}
前台:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
CellPadding="3" Height="1px" PageSize="6" OnRowDeleting="GridView1_RowDeleting" OnRowCreated="GridView1_RowCreated" DataKeyNames="ftID" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" OnRowDataBound="GridView1_RowDataBound" OnPageIndexChanging="GridView1_PageIndexChanging">
<FooterStyle BackColor="White" ForeColor="#000066" />
<Columns>
<asp:BoundField DataField="ftID" HeaderText="发帖ID" />
<asp:BoundField DataField="userName" HeaderText="发帖人">
<ItemStyle width="100px" HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="ftTitle" HeaderText="发帖标题">
<ItemStyle Width="100px" HorizontalAlign="Left" />
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="ftContent" HeaderText="发帖内容">
<HeaderStyle Width="250px" HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="ftDate" HeaderText="发帖时间">
<ItemStyle Width="150px" HorizontalAlign="Left" />
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:CommandField HeaderText="查看内容" ShowDeleteButton="True" DeleteText="查看内容" >
<ItemStyle HorizontalAlign="Center" Width="150px" />
</asp:CommandField>
</Columns>
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
</asp:GridView>
请问为什么在最底下不会出现分页数字1,2,3, 是自动套用格式,AllowPaging="True" 系统的数据大于一页,如果把pagesize改成2 ,就只显示2条了,求教~帖子ID 帖子标题 1 aaa
2 bbb
... ...1 2 3
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
getdate();
}
} protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string ftID = GridView1.DataKeys[e.RowIndex].Value.ToString();
Response.Redirect("~/luntanlook.aspx?ftID=" + ftID);
}
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[0].Visible = false;
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{ if (Session["userid"] == null)
{
Response.Write("<script>alert('请先登录!');location.href='luntan.aspx';</script>");
}
else
{
Response.Redirect("~/AddNewT.aspx");
}
}
protected void getdate()
{
DataSet ds = DB.reDs("select ftID,ftuserID,ftTitle,ftContent,ftDate,userName from FT,Users where FT.ftuserID=Users.userID order by ftDate desc");
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//高亮显示指定行
e.Row.Attributes.Add("onMouseOver", "Color=this.style.backgroundColor;this.style.backgroundColor='#FFF000'");
e.Row.Attributes.Add("onMouseOut", "this.style.backgroundColor=Color;");
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
getdate();
}
}
前台:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
CellPadding="3" Height="1px" PageSize="6" OnRowDeleting="GridView1_RowDeleting" OnRowCreated="GridView1_RowCreated" DataKeyNames="ftID" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" OnRowDataBound="GridView1_RowDataBound" OnPageIndexChanging="GridView1_PageIndexChanging">
<FooterStyle BackColor="White" ForeColor="#000066" />
<Columns>
<asp:BoundField DataField="ftID" HeaderText="发帖ID" />
<asp:BoundField DataField="userName" HeaderText="发帖人">
<ItemStyle width="100px" HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="ftTitle" HeaderText="发帖标题">
<ItemStyle Width="100px" HorizontalAlign="Left" />
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="ftContent" HeaderText="发帖内容">
<HeaderStyle Width="250px" HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="ftDate" HeaderText="发帖时间">
<ItemStyle Width="150px" HorizontalAlign="Left" />
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:CommandField HeaderText="查看内容" ShowDeleteButton="True" DeleteText="查看内容" >
<ItemStyle HorizontalAlign="Center" Width="150px" />
</asp:CommandField>
</Columns>
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
</asp:GridView>
请问为什么在最底下不会出现分页数字1,2,3, 是自动套用格式,AllowPaging="True" 系统的数据大于一页,如果把pagesize改成2 ,就只显示2条了,求教~帖子ID 帖子标题 1 aaa
2 bbb
... ...1 2 3
更改GrdView控件的PageSize属性为 任意数值(默认为10)
更改GrdView控件的PageSetting- >Mode为Numeric等(默认为Numeric)该属性为分页样式。
OnPageIndexChanging="GridView1_PageIndexChanging"
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
InitPage();
}
GridView1.PageIndex = e.NewPageIndex;
更改GrdView控件的PageSize属性为 任意数值(默认为10)
更改GrdView控件的PageSetting- >Mode为Numeric等(默认为Numeric)该属性为分页样式。
OnPageIndexChanging="GridView1_PageIndexChanging"