The design steps are as follows:
1. Connect to the database in C. For example:
2. Add a new item to the project, create a dataset, drag Categories from the server resource list to the dataset template, and click "generate-generate solution" in the menu, for example:
3. Put an ObjectDataSource control on aspx's webform and set its TypeName to the dataset type just created. Use its Wizard to create it.
4. Place a Repeater control on the aspx webform and use its Wizard to set its performanceid to the ObjectDataSource above.
5. set its source code on the webpage, that is, add templates such as <itemTemplate> <AlternatingItemTemplate>. The following code:
Copy codeThe Code is as follows:
<% @ 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 = "objectperformance1" runat = "server"
OldValuesParameterFormatString = "original _ {0}" SelectMethod = "GetData"
TypeName = "Repeater. DataSetEmployeesTableAdapters. CategoriesTableAdapter">
</Asp: ObjectDataSource>
<Asp: Repeater ID = "Repeater1" runat = "server" performanceid = "objectperformance1"
Onitemdatabound = "repeaterincluitemdatabound"
Onitemcreated = "repeaterincluitemcreated">
<HeaderTemplate>
Category Table
<Table border = "1"> <th> category ID </th> <th> category name </th> <th> description </th> <th> image </ 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> '/> </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"> '/> </td>
</Tr>
</AlternatingItemTemplate>
<FooterTemplate>
</Table>
</FooterTemplate>
</Asp: Repeater>
</Div>
</Form>
</Body>
</Html>
7. If the edit box with "O" in the category name is red, write the following code:
Copy codeThe Code is as follows:
Protected void repeaterincluitemdatabound (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. The running result is as follows: