首先說明一下我是asp.net菜鳥,寫文章純粹是為了把學(xué)過的東西記錄下來,方便以后忘記的時(shí)候可以回頭再來看看。
合山網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián)公司,合山網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為合山數(shù)千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站制作要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的合山做網(wǎng)站的公司定做!
這里講的Repeater控件并不是詳解,而是一個(gè)最基礎(chǔ)的使用,下面根據(jù)我寫的小例子來講。
數(shù)據(jù)庫(kù)為自己寫的TestDatabase。
前臺(tái)代碼為
<asp:Repeater ID="Repeater1" runat="server" > <HeaderTemplate> <table id="Table1" > <tr > <th>球員ID</th> <th>球員姓名</th> <th>所在球隊(duì)</th> <th>球衣號(hào)碼</th> <th>場(chǎng)上位置</th> <th>出生日期</th> <th>身高</th> <th>體重</th> <th>是否退役</th> <th>投籃命中率</th> </tr> </HeaderTemplate> <ItemTemplate> <tr > <td><asp:label id="label1" runat="server" text='<%#Eval("PL_ID")%>'/> </td> <td><asp:label id="label3" runat="server" text='<%#Eval("PL_NAME")%>'/> </td> <td><asp:label id="label2" runat="server" text='<%#Eval("TEAM") %>'/> </td> <td><asp:label id="label4" runat="server" text='<%#Eval("PL_NO")%>'/> </td> <td><asp:label id="label5" runat="server" text='<%#Eval("POSITION")%>'/> </td> <td><asp:label id="label6" runat="server" text='<%#IsNull2NA(Eval("BIRTHDAY").ToString())%>'/> </td> <td><asp:textbox id="label7" runat="server" text='<%#IsNull2NA(Eval("HEIGHT").ToString())%>'/> </td> <td><asp:label id="label8" runat="server" text='<%#IsNull2NA(Eval("WEIGHT").ToString())%>'/> </td> <td><asp:RadioButton ID="RadioButton1" runat="server" Checked='<%#IsTOrF(Eval("retired").ToString())%>' Enabled="false"/></td> <td><asp:label id="label9" runat="server" text='<%#Eval("shoot_per")%>'/></td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater>
針對(duì)上面的代碼我有兩點(diǎn)要說明,
1、Repeater的標(biāo)簽元素:其中我們看到了<HeaderTemplate></HeaderTemplate>,<ItemTemplate></ItemTemplate>,
<FooterTemplate></FooterTemplate> ,這幾個(gè)標(biāo)簽,如果不加<HeaderTemplate>和<FooterTemplate>這兩個(gè)標(biāo)簽,用<ItemTemplate> 包在最外面的話,將會(huì)出現(xiàn)下面情況
所以要按照我寫的用<HeaderTemplate></HeaderTemplate> 把<table> 和<th>的內(nèi)容都包含進(jìn)去
2、關(guān)于<%# Eval() %>引用后臺(tái)代碼:因?yàn)槲艺{(diào)用這個(gè)的時(shí)候是為了給Text屬性賦值,但是由于沒有經(jīng)驗(yàn),我在<%# Eval() %>周圍加上了"" ,實(shí)際上應(yīng)該是'',這個(gè)大家一定要注意。
后臺(tái)代碼為
protected void Page_Load(object sender, EventArgs e) { string conn = WebConfigurationManager.ConnectionStrings["TestDatabaseConnectionString"].ConnectionString; SqlConnection myConn = new SqlConnection(conn); myConn.Open(); string sql = "select * from NBA_PLAYER_TBL where PL_NO>'12'"; SqlDataAdapter adp = new SqlDataAdapter(sql, conn); DataSet ds = new DataSet(); adp.Fill(ds); Repeater1.DataSource = ds; Repeater1.DataBind(); myConn.Close(); } public string IsNull2NA(string inStr) { if (inStr == "") { return "NA"; } return inStr; } public Boolean IsTOrF(string inC) { if (inC== 'T'.ToString()) { return true; } return false; }
后臺(tái)代碼相對(duì)來說是比較基礎(chǔ)的內(nèi)容,只要記得要有Repeater的DataBind()操作就行了。
結(jié)果
做的比較丑,但是基本功能都已經(jīng)實(shí)現(xiàn)。
當(dāng)前標(biāo)題:asp.net關(guān)于Repeater數(shù)據(jù)控件實(shí)用
標(biāo)題鏈接:http://jinyejixie.com/article12/gdjegc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供建站公司、網(wǎng)站改版、面包屑導(dǎo)航、品牌網(wǎng)站制作、網(wǎng)站維護(hù)、外貿(mào)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)