复制代码 代码如下:
<asp:DataList runat="server" OnItemDataBound="dlDetailedInfo_ItemDataBound">
<ItemTemplate>
<table cellpadding="0" cellspacing="0">
<tr>
<th colspan="2" scope="col">
数据库绑定到DataList控件 </th>
</tr>
<tr>
<td>
数据库绑定到DataList控件 </td>
<td>
<asp:Label runat="server" Text='<%# Eval("TypeName") %>'></asp:Label>
</td><!--数据库绑定到DataList控件 </tr>
</table>
</ItemTemplate>
</asp:DataList>
复制代码 代码如下:
public void dlBind()
{
int curpage = Convert.ToInt32(this.labPage.Text);
PagedDataSource ps教程 = new PagedDataSource();
sqlcon = new SqlConnection(strCon);
sqlcon.Open();
string sqlstr = "select a.*,b.* from tb_Card as a join tb_Module as b on a.ModuleID=b.ModuleID";
SqlDataAdapter MyAdapter = new SqlDataAdapter(sqlstr, sqlcon);
DataSet ds = new DataSet();
MyAdapter.Fill(ds, "tb_Card");
ps.DataSource = ds.Tables["tb_Card"].DefaultView;
ps.AllowPaging = true; //是否可以分页
ps.PageSize = 2; //显示的数量
ps.CurrentPageIndex = curpage - 1; //取得当前页的页码
this.lnkbtnUp.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.labBackPage.Text = Convert.ToString(ps.PageCount);
this.dlContent.DataSource = ps;
this.dlContent.DataKeyField = "CardID";
this.dlContent.DataBind();
sqlcon.Close();
}
新闻热点
疑难解答
图片精选