| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 480 人关注过本帖
标题:[求助]一个关于dataList中项摸板使用用户控件后自定义分页的问题.
取消只看楼主 加入收藏
airfei
Rank: 1
等 级:新手上路
帖 子:137
专家分:0
注 册:2007-4-12
收藏
 问题点数:0 回复次数:0 
[求助]一个关于dataList中项摸板使用用户控件后自定义分页的问题.

我建立了个用户控件,然后把他放在了datalist的项摸板中,再对datalist进行分页,代码如下:
用户控件book.ascx

<table border="0" cellpadding="0" cellspacing="0" style="width: 317px; position: relative;
height: 131px; left: 0px; top: 0px;">
<tr>
<td style="width: 200px" rowspan = "6">
<asp:Image ID="Image1" runat="server" Style="position: relative" Width="150px" Height="100px" /></td>
<td style="width: 161px;">
<asp:Label ID="Label1" runat="server" Style="position: relative" Text="科目名称:" Width="80px"></asp:Label></td>
<td style="width: 100%;">
<asp:Label ID="lblSubject" runat="server" Style="position: relative; top: 0px;"></asp:Label></td>
</tr>
<tr>

<td style="width: 161px; ">
<asp:Label ID="Label2" runat="server" Style="position: relative" Text="课件标题:" Width="80px"></asp:Label></td>
<td style="width: 100%;">
<asp:Label ID="lblTitle" runat="server" Style="position: relative; top: 0px;"></asp:Label></td>
</tr>
<tr>

<td style="width: 161px;">
<asp:Label ID="Label3" runat="server" Style="position: relative" Text="任课教师:" Width="80px"></asp:Label></td>
<td style="width: 100%;">
<asp:Label ID="lblTeacher" runat="server" Style="position: relative; top: 1px;"></asp:Label></td>
</tr>
<tr>

<td style="width: 161px">
<asp:Label ID="Label4" runat="server" Style="position: relative" Text="上传日期:"></asp:Label></td>
<td style="width: 100%">
<asp:Label ID="lblInput_time" runat="server" Style="position: relative; top: 0px;"></asp:Label></td>
</tr>
<tr>

<td style="width: 161px; height: 19px;">
<asp:Label ID="Label5" runat="server" Style="position: relative" Text="在线阅读:" Width="80px"></asp:Label></td>
<td style="width: 100%; height: 19px;">
<asp:HyperLink ID="hlinkDetails" runat="server" Style="position: relative; top: 0px;" Target="_blank">点击这里...</asp:HyperLink></td>
</tr>
<tr>

<td style="width: 100%;" colspan ="2">
</td>

</tr>
</table>

book.ascx.cs
public partial class student_book : System.Web.UI.UserControl
{
string courseTitle;
public string CourseTitle
{
set
{
this.courseTitle = value.ToString();
}
}

string courseSubject;
public string CourseSubject
{
set
{
this.courseSubject = value.ToString();
}
}

string uploader;
public string Uploader
{
set
{
this.uploader = value.ToString();
}
}

protected void Page_Load(object sender, EventArgs e)
{

SqlConnection con = DB.CreateDB();
con.Open();

SqlCommand cmd = new SqlCommand("select * from courseWare where courseTitle='" + this.courseTitle + "'and courseSubject='"+ this.courseSubject+"'and uploader='"+ this.uploader+"'", con);
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
this.lblSubject.Text = sdr.GetString(2);
this.lblTitle.Text = sdr.GetString(1);
this.lblTeacher.Text = sdr.GetString(5);
this.lblInput_time.Text = sdr.GetDateTime(6).ToShortDateString();
this.Image1.ImageUrl = sdr.GetString(4);
}
sdr.Close();
con.Close();

this.hlinkDetails.NavigateUrl = "LearnDetalis.aspx?Title=" + Server.UrlEncode(this.courseTitle) + "& Subject="+ Server.UrlEncode(this.courseSubject) + "&uploader="+ Server.UrlEncode(this.uploader);

}
}

datalist的分页代码是
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.currentPage.Text = "1";
this.DataBindToDataList();
}
}
private void DataBindToDataList()
{
int curPage = Convert.ToInt32(this.currentPage.Text);
SqlConnection con = DB.CreateDB();
con.Open();

SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = new SqlCommand("select * from courseWare order by input_time Desc,courseId Desc", con);
DataSet ds = new DataSet();
sda.Fill(ds, "course");


//对PagedDataSource 对象的相关属性赋值
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables["course"].DefaultView;
pds.AllowPaging = true;
pds.PageSize = 4;

pds.CurrentPageIndex = curPage - 1;
this.lbtn_next.Visible = true;
this.lbtn_prior.Visible = true;
if (curPage == 1)
{
this.lbtn_prior.Visible = false;
}
if (curPage == pds.PageCount)
{
this.lbtn_next.Visible = false;
}
this.DataList1.DataSource = pds;
this.DataList1.DataBind();

con.Close();
}
protected void lbtn_next_Click(object sender, EventArgs e)
{
this.currentPage.Text = Convert.ToString( Convert.ToInt32(this.currentPage.Text) + 1);
this.DataBindToDataList();
}
protected void lbtn_prior_Click(object sender, EventArgs e)
{
this.currentPage.Text = Convert.ToString(Convert.ToInt32(this.currentPage.Text) - 1);
this.DataBindToDataList();
}

这是分页传递的参数CourseTitle,CourseSubject,Uplaoder
<table border="1" cellpadding="0" cellspacing="0" style="left: 30px; width: 700px;
position: relative; top: 30px">
<tr>
<td style="width: 100%" align="center">
<asp:DataList ID="DataList1" runat="server" RepeatColumns="2" Style="position: relative" ShowFooter="False" ShowHeader="False">
<ItemTemplate>
<uc1:book ID="Book1" runat="server" CourseTitle='<%# Eval("courseTitle","{0}") %>' CourseSubject='<%# Eval("courseSubject","{0}") %>' Uploader='<%# Eval("uploader","{0}") %>'/>
</ItemTemplate>
<AlternatingItemTemplate>
<uc1:book ID="Book2" runat="server" CourseTitle='<%# Eval("courseTitle","{0}") %>' CourseSubject='<%# Eval("courseSubject","{0}") %>' Uploader='<%# Eval("uploader","{0}") %>'/>
</AlternatingItemTemplate>
</asp:DataList>
<asp:Label ID="Label2" runat="server" Style="position: relative" Text="当前页:"></asp:Label>
<asp:Label ID="currentPage" runat="server" Style="position: relative" ></asp:Label>
<asp:LinkButton ID="lbtn_next" runat="server" Style="position: relative" OnClick="lbtn_next_Click">下一页</asp:LinkButton>
<asp:LinkButton ID="lbtn_prior" runat="server" Style="position: relative" OnClick="lbtn_prior_Click">上一页</asp:LinkButton></td>
</tr>
</table>


现在的问题是第一次打开页面时,数据有.但是我点击下一页就没有数据传进来.
我是在datalist中调用用户控件.

大家帮我看看什么问题,和我一样不明白的可以听知道的人讲讲学习下.谢谢大家

搜索更多相关主题的帖子: dataList 控件 定义 用户 
2007-04-30 19:41
快速回复:[求助]一个关于dataList中项摸板使用用户控件后自定义分页的问题.
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.046510 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved