濮阳杆衣贸易有限公司

主頁 > 知識(shí)庫 > asp.net Repeater 數(shù)據(jù)綁定的具體實(shí)現(xiàn)(圖文詳解)

asp.net Repeater 數(shù)據(jù)綁定的具體實(shí)現(xiàn)(圖文詳解)

熱門標(biāo)簽:長(zhǎng)春呼叫中心外呼系統(tǒng)哪家好 萊蕪?fù)夂綦婁N機(jī)器人價(jià)格 智能電話營(yíng)銷外呼系統(tǒng) 五常地圖標(biāo)注 戶外地圖標(biāo)注軟件手機(jī)哪個(gè)好用 凱立德導(dǎo)航官網(wǎng)地圖標(biāo)注 鄭州400電話辦理 聯(lián)通 電銷語音自動(dòng)機(jī)器人 地圖標(biāo)注和認(rèn)領(lǐng)

以下為設(shè)計(jì)步驟:

1、在C# 中連接數(shù)據(jù)庫。如下圖:
2、在項(xiàng)目中添加新建項(xiàng),建立一個(gè)數(shù)據(jù)集,并把Categories從服務(wù)器資源列表中拖到這個(gè)數(shù)據(jù)集模板中并點(diǎn)擊菜單“生成-生成解決方案”,如下圖:

3、在aspx的webform上放一個(gè)ObjectDataSource控件,設(shè)定它的TypeName為剛剛建立的數(shù)據(jù)集類型,用它的向?qū)Ы⒓纯伞?BR>4、在aspx的webform上放一個(gè)Repeater控件,用它的向?qū)гO(shè)定它的DataSourceID為上面的ObjectDataSource
5、在網(wǎng)頁中設(shè)定它的源碼,即加上itemTemplate>AlternatingItemTemplate>等模板。如下面的代碼:

復(fù)制代碼 代碼如下:

%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Repeater.Default" %>

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

html xmlns="http://www.w3.org/1999/xhtml">
head runat="server">
    title>/title>
/head>
body>
    form id="form1" runat="server">
    div>

        asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
            OldValuesParameterFormatString="original_{0}" SelectMethod="GetData"
            TypeName="Repeater.DataSetEmployeesTableAdapters.CategoriesTableAdapter">
        /asp:ObjectDataSource>
        asp:Repeater ID="Repeater1" runat="server" DataSourceID="ObjectDataSource1"
            onitemdatabound="Repeater1_ItemDataBound"
            onitemcreated="Repeater1_ItemCreated">
        HeaderTemplate>
           類別表
           table border="1">th>類別ID/th>th>類別名稱/th>th>描述/th>th>圖片/th>
        /HeaderTemplate>
        ItemTemplate>
           tr>
             td>%#Eval("CategoryID")%>/td>
             td>
                 asp:TextBox ID="TextBox1" runat="server" Text='%#Eval("CategoryName")%>'>/asp:TextBox>
             /td>
             td>%#Eval("Description")%>/td>
             td>img alt="None" src='%#Eval("Picture")%>' />/td>
           /tr>

        /ItemTemplate>
        AlternatingItemTemplate>
           tr>
             td style="background-color:Blue">%#Eval("CategoryID")%>/td>
             td  style="background-color:Blue">
               asp:TextBox ID="TextBox1" runat="server" Text='%#Eval("CategoryName")%>'>/asp:TextBox>
             /td>
             td  style="background-color:Blue">%#Eval("Description")%>/td>
             td  style="background-color:Blue">img alt="None" src='%#Eval("Picture")%>' />/td>
           /tr>
        /AlternatingItemTemplate>
        FooterTemplate>
          /table>
        /FooterTemplate>
        /asp:Repeater>

    /div>
    /form>
/body>
/html>


7、要求在類別名稱中帶"O"的編輯框顯示紅色,則寫出以下代碼:
復(fù)制代碼 代碼如下:

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem)
            {

                TextBox tb = (TextBox)e.Item.FindControl("TextBox1");
                if (tb.Text.Contains("o"))
                {
                    tb.BackColor = Color.Red;
                }

            }
        }


7、運(yùn)行顯示的效果為:

您可能感興趣的文章:
  • ASP.NET repeater添加序號(hào)列的方法
  • asp.net Repeater取得CheckBox選中的某行某個(gè)值的c#寫法
  • asp.net repeater手寫分頁實(shí)例代碼
  • asp.net Repeater之非常好的數(shù)據(jù)分頁
  • asp.net中讓Repeater和GridView支持DataPager分頁
  • asp.net 遍歷repeater中的控件的幾種方式
  • asp.net下Repeater使用 AspNetPager分頁控件
  • asp.net repeater實(shí)現(xiàn)批量刪除
  • asp.net Repeater控件的說明及詳細(xì)介紹及使用方法
  • asp.net Repeater 數(shù)據(jù)綁定代碼
  • JQuery實(shí)現(xiàn)Repeater無刷新批量刪除(附后臺(tái)asp.net源碼)
  • 決定何時(shí)使用 DataGrid、DataList 或 Repeater(ASP.NET 技術(shù)文章)
  • ASP.NET筆記之 Repeater的使用
  • asp.net DataList與Repeater用法區(qū)別
  • 詳解ASP.NET數(shù)據(jù)綁定操作中Repeater控件的用法

標(biāo)簽:紅河 宣城 西藏 湖州 岳陽 西寧 福州 衢州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《asp.net Repeater 數(shù)據(jù)綁定的具體實(shí)現(xiàn)(圖文詳解)》,本文關(guān)鍵詞  asp.net,Repeater,數(shù)據(jù),綁,定的,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《asp.net Repeater 數(shù)據(jù)綁定的具體實(shí)現(xiàn)(圖文詳解)》相關(guān)的同類信息!
  • 本頁收集關(guān)于asp.net Repeater 數(shù)據(jù)綁定的具體實(shí)現(xiàn)(圖文詳解)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    五原县| 涟水县| 呼和浩特市| 鄂尔多斯市| 大丰市| 启东市| 栖霞市| 日照市| 淮阳县| 平原县| 哈巴河县| 彰武县| 屏山县| 翁牛特旗| 嘉义县| 雅江县| 大同县| 香河县| 慈利县| 开原市| 永和县| 化州市| 澄江县| 涞水县| 上犹县| 江城| 陵水| 香港 | 婺源县| 灵寿县| 临洮县| 景东| 色达县| 浦城县| 盖州市| 兴海县| 上思县| 连江县| 南充市| 娄烦县| 九江县|