datalist databind()
解决方法2:
查看MSDN上的详细说明资料
解决方法3:
在DataList的模板中用table表格,如:
<asp:DataList ID="dlDetailedInfo" runat="server" OnItemDataBound="dlDetailedInfo_ItemDataBound" Width="100%">
<ItemTemplate>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="TablebTitle">
<tr>
<th colspan="2" scope="col">
数据库绑定到DataList控件 </th>
</tr>
<tr>
<td width="25%" class="TableGrayRight">
数据库绑定到DataList控件 </td>
<td class="TableNoneLeft">
<asp:Label ID="lblTypeName" runat="server" Text='<%# Eval("TypeName") %>'></asp:Label>
</td><!--数据库绑定到DataList控件 </tr>
</table>
</ItemTemplate>
</asp:DataList>
解决方法4:
你的控件的text使用<%# Eval(" IT从业者之家(www.3ppt.com") %>
比如:txext='<%# Eval("title")%>'
绑定分页实现
dlBind方法为自定义的无返回值类型方法,该方法主要用来从数据库中查询出符合指定条件的记录,并绑定到DataList控件中,然后通过设置 PagedDataSource类对象的AllowPaging属性为True,来实现DataList控件的分页功能。dlBind方法实现代码如下:
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();
}