<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();
}
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com