Bind Repeater to database and repeater to database
Front-end:
<Table width = "650" border = "1"> <tr> <td class = "tr1"> <asp: label Text = "name" runat = "server"> </asp: Label> </td> </tr> </table> <asp: repeater ID = "Repeater1" runat = "server"> <ItemTemplate> <table border = "1" width = "650"> <tr> <td class = "tr1"> <% # Eval ("E_Name ") %> </td> </tr> </table> </ItemTemplate> </asp: Repeater>
Background:
Protected void Page_Load (object sender, EventArgs e)
{
If (! IsPostBack)
{
String connString = "server = .; database = ComInfo; integrated security = true "; // connection String SqlConnection conn = new SqlConnection (connString); // create a connection String strsql =" select E_Name from Emp "; // SQL statement SqlDataAdapter da = new SqlDataAdapter (strsql, conn); DataSet ds = new DataSet (); da. fill (ds); this. repeater1.DataSource = ds; this. repeater1.DataBind (); // bind
}
}
Data Binding of the repeater control
<Asp: Repeater runat = "server" ID = "cancelist">
<HeaderTemplate>
<Table border = "0" cellpadding = "0" cellspacing = "0" width = "400">
<Tr align = "center">
<Th> serial number </th>
<Th> User Name </th>
<Th> User Name </th>
<Th> mobile phone number </th>
<Th> local bureau </th>
</Tr>
</HeaderTemplate>
<ItemTemplate>
<Tr>
<Td class = "alt"> <% # (Container. ItemIndex + 1) %> </td>
<Td class = "alt"> <% # DataBinder. Eval (Container. DataItem, "user_Id") %> </td>
<Td class = "alt"> <% # DataBinder. Eval (Container. DataItem, "user_Name") %> </td>
<Td class = "alt"> <% # DataBinder. Eval (Container. DataItem, "user_Mobile") %> </td>
<Td class = "alt"> <% # DataBinder. Eval (Container. DataItem, "group_name") %> </td>
</Tr>
</ItemTemplate>
<FooterTemplate>
</Table>
</FooterTemplate>
</Asp: Repeater>
In the cs file, export elist. DataSource = dt. DefaultView; dt is the data source table.
C # repeater binding
Wshj847152 is correct;
<Div>
<Asp: Repeater ID = "Repeater1" runat = "server">
<ItemTemplate>
<% -- Set the template columns, and the repeater control will repeat these template columns -- %>
<Table>
<Tr>
<Td>
<% # Eval ("Question") %> <% -- bind a field in your data column database table -- %>
</Td>
</Tr>
<Tr>
<Td>
<% # Eval ("AnswerA") %>
</Td>
</Tr>
<Tr>
<Td>
<% # Eval ("AnswerB") %>
</Td>
</Tr>
<Tr>
<Td>
<% # Eval ("AnswerC") %>
</Td>
</Tr>
<Tr>
<Td>
<% # Eval ("AnswerC") %>
</Td>
</Tr>
</Table>
</ItemTemplate>
</Asp: Repeater>
</Div>
If you do not know how the Repeater generates the template column, you can view the source code of the page (view the source code in the browser)
You will understand how Repeater works.
Change
<Div ...... remaining full text>