我想把AspNetPager与DataList结合使用.但是只做了一部分就不会了,哪位高手能指教?
1、页面代码如下:
<asp:DataList ID="DataList1" runat="server" RepeatDirection="Horizontal" RepeatColumns="2" Width="100%">
<ItemStyle Width="50%"/>
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem,"title")%>
<hr>
</ItemTemplate>
</asp:DataList>
<webdiyer:aspnetpager id="AspNetPager1" runat="server" horizontalalign="Center" onpagechanged="AspNetPager1_PageChanged"
width="100%"></webdiyer:aspnetpager>
2、后台代码如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindData();
}
} void bindData()
{
string sql1 = "select top 8 * from info order by hits,id desc";
OleDbDataAdapter da1 = new OleDbDataAdapter(sql1, my_conn);
DataSet ds1 = new DataSet();
da1.Fill(ds1, "info");
this.DataList1.DataSource = ds1.Tables["info"].DefaultView;
this.DataList1.DataBind();
}
接下来还要怎么做才能实现最终效果?谢谢!!
1、页面代码如下:
<asp:DataList ID="DataList1" runat="server" RepeatDirection="Horizontal" RepeatColumns="2" Width="100%">
<ItemStyle Width="50%"/>
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem,"title")%>
<hr>
</ItemTemplate>
</asp:DataList>
<webdiyer:aspnetpager id="AspNetPager1" runat="server" horizontalalign="Center" onpagechanged="AspNetPager1_PageChanged"
width="100%"></webdiyer:aspnetpager>
2、后台代码如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindData();
}
} void bindData()
{
string sql1 = "select top 8 * from info order by hits,id desc";
OleDbDataAdapter da1 = new OleDbDataAdapter(sql1, my_conn);
DataSet ds1 = new DataSet();
da1.Fill(ds1, "info");
this.DataList1.DataSource = ds1.Tables["info"].DefaultView;
this.DataList1.DataBind();
}
接下来还要怎么做才能实现最终效果?谢谢!!
解决方案 »
- 获得Window.Confirm的值
- asp.net中使用.ajax传参,从后台获得list数据,如何显示
- .net Image控件 控制图片显示
- 为什么我的数据类型"text"只能存储16个字符?
- 一个水问题
- Reporting Services中参数的获取问题
- 到两个帖子拿分:如何将Gridview编辑状态中的控件的OldValue传递给ObjectDataSource的UpdateParameters?
- 請教樹形報表
- 请问怎样取得gridview中的dropdownlist的值
- .net 下载附件后,刷新当前页面
- Response.Write()有啥具体的用?在asp.net里!
- 如何在Listbox的每一项的后面加一个小箭头
AspNetPager用法你拿走
http://www.cnblogs.com/wennxxin/archive/2008/10/16/1312954.html
http://www.cnblogs.com/ly5201314/archive/2008/09/09/1287450.html
http://download.csdn.net/sort/tag/AspNetPager
http://download.csdn.net/source/134663
http://download.csdn.net/source/386421
protected void AspNetPager1_PageChanged(object src, EventArgs e)
{
bindData();
}
Font-Size="9pt" Font-Names="宋体" FirstPageText="首页" LastPageText="尾页"
NextPageText="下一页" PageIndexBoxType="TextBox" PrevPageText="上一页"
ShowPageIndexBox="Always" SubmitButtonText="跳转" TextAfterPageIndexBox="页"
TextBeforePageIndexBox="转到" ShowNavigationToolTip="True" CenterCurrentPageButton="True">
</webdiyer:AspNetPager> Private Function GetBindData(ByVal getMax As Boolean) As DataSet
Dim lnkSqlConnStr As String = System.Configuration.ConfigurationManager.ConnectionStrings("LocalSqlServer").ToString().Trim()
Dim conn As SqlConnection = New SqlConnection(lnkSqlConnStr)
conn.Open()
Try
Dim styleId As String = ""
Dim keyword As String = "" styleId = Request.QueryString("styleId")
keyword = IIf(Request.QueryString("keyword") = Nothing, "", Request.QueryString("keyword")) Dim tmpDataTable As New DataTable()
Dim doSql As String doSql = "select * from Hotel where IsDele=0 " If keyword.Trim() <> "" Then
doSql += " and Name like '%" & keyword & "%'"
End If doSql += " order by Id"
Dim myset As DataSet = New DataSet()
Dim myadp As SqlDataAdapter = New SqlDataAdapter(doSql, conn)
If getMax = True Then
myadp.Fill(myset, "rntable")
Else
myadp.Fill(myset, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "rntable")
End If Return myset Catch ex As Exception
conn.Close()
Return Nothing
Finally
conn.Close()
End Try
End Function
Private Sub DoBind()
Try
Dim tmpSet As DataSet = New DataSet()
tmpSet = GetBindData(False)
If Not tmpSet Is Nothing Then
Me.DataListAttractionsDisp.DataKeyField = "Id" '定义主键
Me.DataListAttractionsDisp.DataSource = tmpSet.Tables(0)
Me.DataListAttractionsDisp.DataBind()
End If
Catch ex As Exception End Try
End Sub
Protected Sub AspNetPager1_PageChanging(ByVal src As Object, ByVal e As Wuqi.Webdiyer.PageChangingEventArgs) Handles AspNetPager1.PageChanging
AspNetPager1.CurrentPageIndex = e.NewPageIndex
GetBindData(False)
DoBind()
End Sub