Asp.net for Repeater Data Controls

Source: Internet
Author: User

First of all, I am asp.net cainiao. I wrote articles purely to record what I have learned so that I can come back later when I forget it.

The Repeater control mentioned here is not a detailed explanation, but a basic usage. The following is a small example.

The database is a self-written TestDatabase.

The front-end code is

<Asp: repeater ID = "Repeater1" runat = "server"> <HeaderTemplate> <table id = "Table1"> <tr> <th> player ID </th> <th> player name </th> <th> Team </th> <th> jersey number </th> <th> place on the court </th> <th> Date of Birth </th> <th> height </th> <th> weight </th> <th> retired </th> <th> shooting hit rate </th> </tr> </ headerTemplate> <ItemTemplate> <tr> <td> <asp: label id = "label1" runat = "server" text = '<% # Eval ("PL_ID") %>'/> </td> <asp: label id = "label3" runat = "server" text = '<% # Eval ("PL_NAME") %>'/> </td> <asp: label id = "label2" runat = "server" text = '<% # Eval ("TEAM") %>'/> </td> <asp: label id = "label4" runat = "server" text = '<% # Eval ("PL_NO") %>'/> </td> <asp: label id = "label5" runat = "server" text = '<% # Eval ("POSITION") %>'/> </td> <asp: label id = "label6" runat = "server" text = '<% # IsNull2NA (Eval ("BIRTHDAY "). toString () %> '/> </td> <asp: textbox id = "label7" runat = "server" text = '<% # IsNull2NA (Eval ("HEIGHT "). toString () %> '/> </td> <asp: label id = "label8" runat = "server" text = '<% # IsNull2NA (Eval ("WEIGHT "). toString () %> '/> </td> <asp: radioButton ID = "RadioButton1" runat = "server" Checked = '<% # istdorf (Eval ("retired "). toString () %> 'enabled = "false"/> </td> <asp: label id = "label9" runat = "server" text = '<% # Eval ("shoot_per ") %> '/> </td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp: Repeater>

For the above code, I have two points to explain,

1. Tag Element of Repeater: we can see <HeaderTemplate> </HeaderTemplate>, <ItemTemplate> </ItemTemplate>,

<FooterTemplate> </FooterTemplate>. If the <HeaderTemplate> and <FooterTemplate> labels are not added, use the <ItemTemplate> package to the outermost part, the following situations will occur:

650) this. length = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/19294H4C-0.png "title =" QQ20130926150657.png "alt =" 153753506.png"/> So according to my write with <HeaderTemplate> </HeaderTemplate> put <table> and <th> content included

2. About <% # Eval () %> reference background code: Because I tried to assign a value to the Text attribute when calling this operation, but I had no experience with it, I added "" around <% # Eval () %>. It should actually be ''. You must pay attention to this.


The background code is

    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;    }

The background code is relatively basic, as long as you remember to have the Repeater DataBind () operation.

Result

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/19294ME5-1.jpg "title =" qq 30926124757.jpg "alt =" 125534540.jpg"/>

It is ugly, but all basic functions have been implemented.

This article is from the "typical lion man" blog, please be sure to keep this source http://zhouhongyu1989.blog.51cto.com/2931598/1302197

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.