求ASP.NET DATALIST 分页代码 或者能把下面代码调试成功
这是个分页控件代码原来的查询语句是select*fromzfl我把他改成select*fromzflwhereflb='"+df+"'"就不好使了只能出现前八条有高手会解...
这是个分页控件代码 原来的查询语句是select * from zfl我把他改成select * from zfl where flb='" + df + "'"就不好使了只能出现前八条
有高手会解决么 我要的分页代码也要使用select * from zfl where flb='" + df + "'"当查询语句的
public string df;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string strconn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + System.Web.HttpContext.Current.Server.MapPath("~/App_Data/Tang.mdb");//连接数据库
OleDbConnection con = new OleDbConnection(strconn);
con.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = con;
df = Server.UrlDecode(Request.QueryString["FID"].ToString());
cmd.CommandText = "SELECT COUNT(*) FROM zfl where flb='" + df + "'";//
pagelist.AlwaysShow = true;
pagelist.PageSize = 8; //显示页数
pagelist.RecordCount = (int)cmd.ExecuteScalar(); //读出数据库里一共有多少条数据
con.Close();
DataBindlist();
}
}
protected void DataBindlist()
{
string strconn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + System.Web.HttpContext.Current.Server.MapPath("~/App_Data/Tang.mdb");//连接数据库
OleDbConnection con = new OleDbConnection(strconn);
OleDbDataAdapter ad = new OleDbDataAdapter("select * from zfl where flb='" + df + "'", con);// order by a.di desc
DataSet ds = new DataSet();
ad.Fill(ds, pagelist.PageSize * (pagelist.CurrentPageIndex - 1), pagelist.PageSize, "zfl");
DataList1.DataSource = ds.Tables["zfl"];
DataList1.DataBind();
}
protected void PageChanging(object src, PageChangingEventArgs e)
{
pagelist.CurrentPageIndex = e.NewPageIndex;
DataBindlist();
}
忘说了我要带这样的 总页数 首页 上一页 1 2 3 4 5 6 下一页 尾页 要是没有人有这个,有人能提供这样的话我还加分 ,那分就给二楼 了 你那个代码我也有 好使 展开
有高手会解决么 我要的分页代码也要使用select * from zfl where flb='" + df + "'"当查询语句的
public string df;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string strconn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + System.Web.HttpContext.Current.Server.MapPath("~/App_Data/Tang.mdb");//连接数据库
OleDbConnection con = new OleDbConnection(strconn);
con.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = con;
df = Server.UrlDecode(Request.QueryString["FID"].ToString());
cmd.CommandText = "SELECT COUNT(*) FROM zfl where flb='" + df + "'";//
pagelist.AlwaysShow = true;
pagelist.PageSize = 8; //显示页数
pagelist.RecordCount = (int)cmd.ExecuteScalar(); //读出数据库里一共有多少条数据
con.Close();
DataBindlist();
}
}
protected void DataBindlist()
{
string strconn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + System.Web.HttpContext.Current.Server.MapPath("~/App_Data/Tang.mdb");//连接数据库
OleDbConnection con = new OleDbConnection(strconn);
OleDbDataAdapter ad = new OleDbDataAdapter("select * from zfl where flb='" + df + "'", con);// order by a.di desc
DataSet ds = new DataSet();
ad.Fill(ds, pagelist.PageSize * (pagelist.CurrentPageIndex - 1), pagelist.PageSize, "zfl");
DataList1.DataSource = ds.Tables["zfl"];
DataList1.DataBind();
}
protected void PageChanging(object src, PageChangingEventArgs e)
{
pagelist.CurrentPageIndex = e.NewPageIndex;
DataBindlist();
}
忘说了我要带这样的 总页数 首页 上一页 1 2 3 4 5 6 下一页 尾页 要是没有人有这个,有人能提供这样的话我还加分 ,那分就给二楼 了 你那个代码我也有 好使 展开
展开全部
<asp:DataList ID="DataList1" runat="server" Width ="100%" style="margin-bottom: 0px"
onselectedindexchanged="DataList1_SelectedIndexChanged1"
onitemdatabound="DataList1_ItemDataBound">
<HeaderStyle Height ="23px" BackColor ="White" />
<ItemStyle Height ="23px" />
<HeaderTemplate>
<table cellspacing="1"
style="width :100%; background-color:#999999; height :23px;">
<tr>
<td style="width :50%; background-color :#A5522A; " >
<asp:Label ID="Label1" runat="server" Text="帖子名称"></asp:Label>
</td>
<td style="width :10%; background-color :#a5522a; text-align :center;">
<asp:Label ID="Label2" runat="server" Text="人气/回复"></asp:Label>
</td>
<td style="width:10%; background-color :#a5522a; text-align :center ;">
<asp:Label ID="Label3" runat="server" Text="发表时间"></asp:Label>
</td>
</tr>
</table>
</HeaderTemplate>
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<ItemStyle Height="24px" />
<ItemTemplate>
<table bgcolor="#FF9900" border="0" cellspacing="1"
style="width:100%; height: 23px;">
<tr>
<td style ="background-color:White;" class="style4">
<asp:CheckBox ID="CheckBox1" runat="server" />
<asp:LinkButton ID="LinkButton3" runat="server" BackColor="White"
CommandName='<%#Eval("ThemePosNo") %>' Font-Bold="False" Font-Italic="False"
Font-Names="宋体" Font-Size="12px" Font-Underline="False"
ForeColor="Black" Text ='<%#Eval("ThemeName") %>'
oncommand="LinkButton3_Command" ></asp:LinkButton>
<asp:Image ID="ImgJing" runat="server" Height="15px"
ImageUrl="~/ForumImages/jing.gif" />
<asp:Image ID="ImgJian" runat="server" ImageUrl="~/ForumImages/jian.gif" />
<asp:Image ID="ImgDing" runat="server" ImageUrl="~/ForumImages/ding.gif"
Width="15px" />
<asp:Image ID="ImgNew" runat="server" ImageUrl="~/ForumImages/new.gif" />
</td>
<td style ="background-color :White;" class="style3">
<asp:Label ID="lblThemeReadCount" runat="server" Font-Size="12px"></asp:Label>
/<asp:Label ID="lblRePos" runat="server" Font-Size="12px"></asp:Label>
</td>
<td style ="background-color :White;" class="style3">
<asp:Label ID="lblTime" runat="server" Font-Size="12px" Text ='<%#Convert.ToDateTime(Eval("ThemeTime")).ToString("yyyy-MM-dd") %>'></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
<table width="100%" height="23px" bordercolor="#FF9900" bgcolor="#FF9900" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#FFFFFF" class="style6">
<asp:LinkButton ID="lnkbtnOne" runat="server" Font-Size="12px"
Font-Underline="False" ForeColor="Black">第一页</asp:LinkButton>
</td>
<td bgcolor="#FFFFFF" class="style6">
<asp:LinkButton ID="lnkbtnUp" runat="server" Font-Size="12px"
Font-Underline="False" ForeColor="Black">上一页</asp:LinkButton>
</td>
<td bgcolor="#FFFFFF" class ="style6">
<asp:LinkButton ID="lnkbtnNext" runat="server" Font-Size="12px"
Font-Underline="False" ForeColor="Black">下一页</asp:LinkButton>
</td>
<td bgcolor="#FFFFFF" class ="style6">
<asp:LinkButton ID="lnkbtnBack" runat="server" Font-Size="12px"
Font-Underline="False" ForeColor="Black">最后一页</asp:LinkButton>
</td>
<td bgcolor="#FFFFFF" class="style8">
<asp:Label ID="Label4" runat="server" Font-Size="12px"
Font-Underline="False" ForeColor="Black" Text="当前页数"></asp:Label>
<asp:Label ID="labpage" runat="server" Font-Size="12px"
Font-Underline="False" ForeColor="Black" Text="1"></asp:Label>/
<asp:Label ID="labzh" runat="server" Font-Size="12px"
Font-Underline="False" ForeColor="Black" Text="Label"></asp:Label>
</td>
<td bgcolor="#FFFFFF">
<asp:TextBox ID="txtPage" runat="server" Width="24px"></asp:TextBox>
<asp:Button ID="btnGo" runat="server" Text="Go" onclick="btnGo_Click"
Width="24px" />
</td>
</tr>
</table>
上面是我Datalist的代码,和点击按钮分页的html代码
下面是我绑定和分页的代码。
public void dlBind()
{
DataSet ds;
if (strForumNoFlag == null)
{
ds = ThemePos.GetThemePosInfo();
}
else
{
ds = ThemePos.ReThemePosInfo(strForumNoFlag);
}
int curpage = Convert.ToInt32(this.labpage.Text);
PagedDataSource ps = new PagedDataSource();
ps.DataSource = ds.Tables[0].DefaultView;
ps.AllowPaging = true;
ps.PageSize = 20;
ps.CurrentPageIndex = curpage - 1;
this.lnkbtnBack.Enabled = true;
this.lnkbtnNext.Enabled = true;
this.lnkbtnBack.Enabled = true;
this.lnkbtnOne.Enabled = true;
if (curpage == 1)
{
this.lnkbtnOne.Enabled = false;
this.lnkbtnUp.Enabled = false;
}
if (curpage == ps.PageCount)
{
this.lnkbtnNext.Enabled = false;
this.lnkbtnBack.Enabled = false;
}
this.labpage.Text = Convert.ToString(ps.PageCount);
this.labzh.Text = Convert.ToString(ps.PageCount);
this.DataList1.DataSource = ps;
this.DataList1.DataBind();
}
protected void lnkbtnOne_Click(object sender, EventArgs e)
{
//显示第一页的内容
this.labpage.Text = "1";
this.dlBind();
}
protected void lnkbtnUp_Click(object sender, EventArgs e)
{
//显示上一页的内容:
this.labpage.Text = Convert.ToString(Convert.ToInt32(this.labpage.Text) - 1);
this.dlBind();
}
protected void lnkbtnNext_Click(object sender, EventArgs e)
{
//分页显示下一页的内容
this.labpage.Text = Convert.ToString(Convert.ToInt32(this.labpage.Text) + 1);
this.dlBind();
}
protected void lnkbtnBack_Click(object sender, EventArgs e)
{
//分页显示最后一页的内容
this.labpage.Text = this.labpage.Text;
this.dlBind();
}
给你提个醒,不知道可以不。
你那个123456你可以动态生成。然后写一些委托事件。
onselectedindexchanged="DataList1_SelectedIndexChanged1"
onitemdatabound="DataList1_ItemDataBound">
<HeaderStyle Height ="23px" BackColor ="White" />
<ItemStyle Height ="23px" />
<HeaderTemplate>
<table cellspacing="1"
style="width :100%; background-color:#999999; height :23px;">
<tr>
<td style="width :50%; background-color :#A5522A; " >
<asp:Label ID="Label1" runat="server" Text="帖子名称"></asp:Label>
</td>
<td style="width :10%; background-color :#a5522a; text-align :center;">
<asp:Label ID="Label2" runat="server" Text="人气/回复"></asp:Label>
</td>
<td style="width:10%; background-color :#a5522a; text-align :center ;">
<asp:Label ID="Label3" runat="server" Text="发表时间"></asp:Label>
</td>
</tr>
</table>
</HeaderTemplate>
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<ItemStyle Height="24px" />
<ItemTemplate>
<table bgcolor="#FF9900" border="0" cellspacing="1"
style="width:100%; height: 23px;">
<tr>
<td style ="background-color:White;" class="style4">
<asp:CheckBox ID="CheckBox1" runat="server" />
<asp:LinkButton ID="LinkButton3" runat="server" BackColor="White"
CommandName='<%#Eval("ThemePosNo") %>' Font-Bold="False" Font-Italic="False"
Font-Names="宋体" Font-Size="12px" Font-Underline="False"
ForeColor="Black" Text ='<%#Eval("ThemeName") %>'
oncommand="LinkButton3_Command" ></asp:LinkButton>
<asp:Image ID="ImgJing" runat="server" Height="15px"
ImageUrl="~/ForumImages/jing.gif" />
<asp:Image ID="ImgJian" runat="server" ImageUrl="~/ForumImages/jian.gif" />
<asp:Image ID="ImgDing" runat="server" ImageUrl="~/ForumImages/ding.gif"
Width="15px" />
<asp:Image ID="ImgNew" runat="server" ImageUrl="~/ForumImages/new.gif" />
</td>
<td style ="background-color :White;" class="style3">
<asp:Label ID="lblThemeReadCount" runat="server" Font-Size="12px"></asp:Label>
/<asp:Label ID="lblRePos" runat="server" Font-Size="12px"></asp:Label>
</td>
<td style ="background-color :White;" class="style3">
<asp:Label ID="lblTime" runat="server" Font-Size="12px" Text ='<%#Convert.ToDateTime(Eval("ThemeTime")).ToString("yyyy-MM-dd") %>'></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
<table width="100%" height="23px" bordercolor="#FF9900" bgcolor="#FF9900" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#FFFFFF" class="style6">
<asp:LinkButton ID="lnkbtnOne" runat="server" Font-Size="12px"
Font-Underline="False" ForeColor="Black">第一页</asp:LinkButton>
</td>
<td bgcolor="#FFFFFF" class="style6">
<asp:LinkButton ID="lnkbtnUp" runat="server" Font-Size="12px"
Font-Underline="False" ForeColor="Black">上一页</asp:LinkButton>
</td>
<td bgcolor="#FFFFFF" class ="style6">
<asp:LinkButton ID="lnkbtnNext" runat="server" Font-Size="12px"
Font-Underline="False" ForeColor="Black">下一页</asp:LinkButton>
</td>
<td bgcolor="#FFFFFF" class ="style6">
<asp:LinkButton ID="lnkbtnBack" runat="server" Font-Size="12px"
Font-Underline="False" ForeColor="Black">最后一页</asp:LinkButton>
</td>
<td bgcolor="#FFFFFF" class="style8">
<asp:Label ID="Label4" runat="server" Font-Size="12px"
Font-Underline="False" ForeColor="Black" Text="当前页数"></asp:Label>
<asp:Label ID="labpage" runat="server" Font-Size="12px"
Font-Underline="False" ForeColor="Black" Text="1"></asp:Label>/
<asp:Label ID="labzh" runat="server" Font-Size="12px"
Font-Underline="False" ForeColor="Black" Text="Label"></asp:Label>
</td>
<td bgcolor="#FFFFFF">
<asp:TextBox ID="txtPage" runat="server" Width="24px"></asp:TextBox>
<asp:Button ID="btnGo" runat="server" Text="Go" onclick="btnGo_Click"
Width="24px" />
</td>
</tr>
</table>
上面是我Datalist的代码,和点击按钮分页的html代码
下面是我绑定和分页的代码。
public void dlBind()
{
DataSet ds;
if (strForumNoFlag == null)
{
ds = ThemePos.GetThemePosInfo();
}
else
{
ds = ThemePos.ReThemePosInfo(strForumNoFlag);
}
int curpage = Convert.ToInt32(this.labpage.Text);
PagedDataSource ps = new PagedDataSource();
ps.DataSource = ds.Tables[0].DefaultView;
ps.AllowPaging = true;
ps.PageSize = 20;
ps.CurrentPageIndex = curpage - 1;
this.lnkbtnBack.Enabled = true;
this.lnkbtnNext.Enabled = true;
this.lnkbtnBack.Enabled = true;
this.lnkbtnOne.Enabled = true;
if (curpage == 1)
{
this.lnkbtnOne.Enabled = false;
this.lnkbtnUp.Enabled = false;
}
if (curpage == ps.PageCount)
{
this.lnkbtnNext.Enabled = false;
this.lnkbtnBack.Enabled = false;
}
this.labpage.Text = Convert.ToString(ps.PageCount);
this.labzh.Text = Convert.ToString(ps.PageCount);
this.DataList1.DataSource = ps;
this.DataList1.DataBind();
}
protected void lnkbtnOne_Click(object sender, EventArgs e)
{
//显示第一页的内容
this.labpage.Text = "1";
this.dlBind();
}
protected void lnkbtnUp_Click(object sender, EventArgs e)
{
//显示上一页的内容:
this.labpage.Text = Convert.ToString(Convert.ToInt32(this.labpage.Text) - 1);
this.dlBind();
}
protected void lnkbtnNext_Click(object sender, EventArgs e)
{
//分页显示下一页的内容
this.labpage.Text = Convert.ToString(Convert.ToInt32(this.labpage.Text) + 1);
this.dlBind();
}
protected void lnkbtnBack_Click(object sender, EventArgs e)
{
//分页显示最后一页的内容
this.labpage.Text = this.labpage.Text;
this.dlBind();
}
给你提个醒,不知道可以不。
你那个123456你可以动态生成。然后写一些委托事件。
展开全部
前面的代码基本和二楼一样,在分页码的地方也放一个datalist,用来绑定页码的,
<td>
共 <asp:Label ID="count" runat="server"></asp:Label> 页
第<asp:Label ID="current" runat="server"></asp:Label>页
<asp:LinkButton ID="first" Text="首 页" OnClick="first_Click" runat="server" />
<asp:LinkButton ID="back" Text="上一页" OnClick="back_Click" runat="server" />
</td>
<td>
<!--绑定页码-->
<asp:DataList ID="datalist" runat="server" OnItemCommand="datalist_ItemCommand" RepeatDirection="Horizontal">
<ItemTemplate>
<asp:LinkButton ID="lblcurr" runat="server" Text='<%# Bind("text") %>' CommandName="pageIndex"></asp:LinkButton>
</ItemTemplate>
</asp:DataList>
<!--绑定页码-->
</td>
<td>
<asp:LinkButton ID="next" Text="下一页" OnClick="next_Click" runat="server"/>
<asp:LinkButton ID="last" Text="末 页" OnClick="last_Click" runat="server" />
</td>
将你取出来的总页数做成集合(pagelist.PageCount),绑定在这个页码的datalist上,
DataTable dt1 = new DataTable();
dt1.Columns.Add("text");
dt1.Columns.Add("value");
int a = 1;
for (int i = 0; i < pagelist.PageCount; i++)
{
DataRow dr = dt1.NewRow();
dr["text"] = a.ToString();
dr["value"] = i.ToString();
a++;
dt1.Rows.Add(dr);
}
datalist.DataSource = dt1;
datalist.DataBind();
在这个datalist的ItemCommand上写事件,让它跳转到pagelist指定的CurrentPageIndex上。
protected void datalist_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "pageIndex")
{
LinkButton lblcurr = (LinkButton)this.datalist.Items[e.Item.ItemIndex].FindControl("lblcurr");//取得所选的页码
pagelist.CurrentPageIndex = Convert.ToInt32(lblcurr.Text) - 1;
DataList1.DataSource = pagelist;
DataList1.DataBind();
}
}
你也可以通过给LinkButton 加上颜色以便于提示用户翻到了第几页,或者在第几页的部分提示下也可以,希望对你有帮助。
<td>
共 <asp:Label ID="count" runat="server"></asp:Label> 页
第<asp:Label ID="current" runat="server"></asp:Label>页
<asp:LinkButton ID="first" Text="首 页" OnClick="first_Click" runat="server" />
<asp:LinkButton ID="back" Text="上一页" OnClick="back_Click" runat="server" />
</td>
<td>
<!--绑定页码-->
<asp:DataList ID="datalist" runat="server" OnItemCommand="datalist_ItemCommand" RepeatDirection="Horizontal">
<ItemTemplate>
<asp:LinkButton ID="lblcurr" runat="server" Text='<%# Bind("text") %>' CommandName="pageIndex"></asp:LinkButton>
</ItemTemplate>
</asp:DataList>
<!--绑定页码-->
</td>
<td>
<asp:LinkButton ID="next" Text="下一页" OnClick="next_Click" runat="server"/>
<asp:LinkButton ID="last" Text="末 页" OnClick="last_Click" runat="server" />
</td>
将你取出来的总页数做成集合(pagelist.PageCount),绑定在这个页码的datalist上,
DataTable dt1 = new DataTable();
dt1.Columns.Add("text");
dt1.Columns.Add("value");
int a = 1;
for (int i = 0; i < pagelist.PageCount; i++)
{
DataRow dr = dt1.NewRow();
dr["text"] = a.ToString();
dr["value"] = i.ToString();
a++;
dt1.Rows.Add(dr);
}
datalist.DataSource = dt1;
datalist.DataBind();
在这个datalist的ItemCommand上写事件,让它跳转到pagelist指定的CurrentPageIndex上。
protected void datalist_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "pageIndex")
{
LinkButton lblcurr = (LinkButton)this.datalist.Items[e.Item.ItemIndex].FindControl("lblcurr");//取得所选的页码
pagelist.CurrentPageIndex = Convert.ToInt32(lblcurr.Text) - 1;
DataList1.DataSource = pagelist;
DataList1.DataBind();
}
}
你也可以通过给LinkButton 加上颜色以便于提示用户翻到了第几页,或者在第几页的部分提示下也可以,希望对你有帮助。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
"select * from zfl where flb=" + df.ToString();
试试这样写
df.Tosting()主要需要这块
试试这样写
df.Tosting()主要需要这块
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询