asp.net中將數(shù)據(jù)庫(kù)綁定到DataList控件的實(shí)現(xiàn)方法與實(shí)例代碼
datalist databind()
解決方法2:
查看MSDN上的詳細(xì)說(shuō)明資料
解決方法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">
數(shù)據(jù)庫(kù)綁定到DataList控件 </th>
</tr>
<tr>
<td width="25%" class="TableGrayRight">
數(shù)據(jù)庫(kù)綁定到DataList控件 </td>
<td class="TableNoneLeft">
<asp:Label ID="lblTypeName" runat="server" Text='<%# Eval("TypeName") %>'></asp:Label>
</td><!--數(shù)據(jù)庫(kù)綁定到DataList控件 </tr>
</table>
</ItemTemplate>
</asp:DataList>
解決方法4:
你的控件的text使用<%# Eval(" IT從業(yè)者之家(www.3ppt.com") %>
比如:txext='<%# Eval("title")%>'
綁定分頁(yè)實(shí)現(xiàn)
dlBind方法為自定義的無(wú)返回值類(lèi)型方法,該方法主要用來(lái)從數(shù)據(jù)庫(kù)中查詢(xún)出符合指定條件的記錄,并綁定到DataList控件中,然后通過(guò)設(shè)置 PagedDataSource類(lèi)對(duì)象的AllowPaging屬性為T(mén)rue,來(lái)實(shí)現(xiàn)DataList控件的分頁(yè)功能。dlBind方法實(shí)現(xiàn)代碼如下:
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; //是否可以分頁(yè)
ps.PageSize = 2; //顯示的數(shù)量
ps.CurrentPageIndex = curpage - 1; //取得當(dāng)前頁(yè)的頁(yè)碼
this.lnkbtnUp.Enabled = true;
this.lnkbtnNext.Enabled = true;
this.lnkbtnBack.Enabled = true;
this.lnkbtnOne.Enabled = true;
if (curpage == 1)
{
this.lnkbtnOne.Enabled = false;//不顯示第一頁(yè)按鈕
this.lnkbtnUp.Enabled = false;//不顯示上一頁(yè)按鈕
}
if (curpage == ps.PageCount)
{
this.lnkbtnNext.Enabled = false;//不顯示下一頁(yè)
this.lnkbtnBack.Enabled = false;//不顯示最后一頁(yè)
}
this.labBackPage.Text = Convert.ToString(ps.PageCount);
this.dlContent.DataSource = ps;
this.dlContent.DataKeyField = "CardID";
this.dlContent.DataBind();
sqlcon.Close();
}
- asp.net中Datalist使用數(shù)字分頁(yè)的實(shí)現(xiàn)方法
- ASP.NET中利用DataList實(shí)現(xiàn)圖片無(wú)縫滾動(dòng) 實(shí)例分享
- ASP.Net 之Datalist刪除功能詳解附代碼
- asp.net datalist綁定數(shù)據(jù)后可以上移下移實(shí)現(xiàn)示例
- 在ASP.NET 2.0中操作數(shù)據(jù)之三十五:使用Repeater和DataList單頁(yè)面實(shí)現(xiàn)主/從報(bào)表
- 在ASP.NET 2.0中操作數(shù)據(jù)之三十六:在DataList里編輯和刪除數(shù)據(jù)概述
- 在ASP.NET 2.0中操作數(shù)據(jù)之三十七:DataList批量更新
- asp.net控件DataList分頁(yè)用法
- 在ASP.NET 2.0中操作數(shù)據(jù)之三十九:在DataList的編輯界面里添加驗(yàn)證控件
- 在ASP.NET 2.0中操作數(shù)據(jù)之四十:自定義DataList編輯界面
相關(guān)文章
asp.net Repeater 數(shù)據(jù)綁定代碼
asp.net Repeater 數(shù)據(jù)綁定代碼2010-03-03一個(gè)伴隨ASP.NET從1.0到4.0的OutputCache Bug介紹
一個(gè)伴隨ASP.NET從1.0到4.0的OutputCache Bug介紹,學(xué)習(xí).net的朋友可以參考下。2011-11-11asp.net 相關(guān)文章實(shí)現(xiàn)方法
大家或許會(huì)覺(jué)得很驚訝:為什么靈感之源會(huì)討論SQL?或許應(yīng)該這樣說(shuō)吧:搞業(yè)務(wù)系統(tǒng),不跟SQL扯上關(guān)系似乎比較難。2009-05-05asp.net UpdatePanel實(shí)現(xiàn)無(wú)刷新上傳圖片
UpdatePanel實(shí)現(xiàn)無(wú)刷新上傳圖片實(shí)現(xiàn)代碼,需要的朋友可以參考下。2010-03-03jQuery調(diào)用WebService返回JSON數(shù)據(jù)及參數(shù)設(shè)置注意問(wèn)題
.NET Framework 3.5的發(fā)布解決了WebService調(diào)用中json問(wèn)題,本文將介紹jQuery調(diào)用基于.NET Framework 3.5的WebService返回JSON數(shù)據(jù),感興趣的朋友可以了解下,希望本文對(duì)你有所幫助2013-01-01asp.net訪問(wèn)網(wǎng)絡(luò)路徑方法(模擬用戶(hù)登錄)
這篇文章主要介紹了asp.net訪問(wèn)網(wǎng)絡(luò)路徑方法,其實(shí)就是模擬用戶(hù)登錄,需要的朋友可以參考下2014-08-08asp.net中“從客戶(hù)端中檢測(cè)到有潛在危險(xiǎn)的Request.Form值”錯(cuò)誤的解決辦法
這篇文章主要介紹了asp.net中“從客戶(hù)端中檢測(cè)到有潛在危險(xiǎn)的Request.Form值”錯(cuò)誤的解決辦法,需要的朋友可以參考下2015-11-11GridView控件實(shí)現(xiàn)數(shù)據(jù)的修改(第9節(jié))
這篇文章主要介紹了GridView控件實(shí)現(xiàn)數(shù)據(jù)的修改,需要的朋友可以參考下2015-08-08.net開(kāi)發(fā)中幾個(gè)重要的認(rèn)識(shí)誤區(qū)小結(jié)
.net如今已經(jīng)很流行,成為趕時(shí)髦的程序員的首選。但是,大量剛剛接觸.net的程序員的確存在一定的認(rèn)識(shí)誤區(qū),這里先介紹一部分。2010-04-04