1 first, and most importantly, introduce the reference code on the aspx page: <% @ Import Namespace = "System. Data" %>
2. Add the Repeater control to the page.
<Asp: Repeater ID = "Rep_Data" runat = "server" OnItemDataBound = "Rep_Data_ItemDataBound" OnItemCommand = "Rep_Data_ItemCommand">
<ItemTemplate>
<Asp: Label ID = "LB_Id" runat = "server" Text = '<% # (DataRowView) Container. dataItem) ["MC_Id"] %> 'visible = "false"> </asp: Label>
<Asp: LinkButton ID = "LB_Title" runat = "server" Text = '<% # (DataRowView) Container. dataItem) ["MC_Title"] %> 'commandname = "Display">
</Asp: LinkButton>
<Br>
</ItemTemplate>
</Asp: Repeater>
3 In fact, the Repeater and the GridView have the same usage as the RowBind and Command events.
/// <Summary>
/// Repeater Data Binding event
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "e"> </param>
Protected void Rep_Data_ItemDataBound (object sender, RepeaterItemEventArgs e)
{
// Set the link column button to input Command Parameters
If (e. Item. ItemType = ListItemType. Item | e. Item. ItemType = ListItemType. AlternatingItem)
{
LinkButton LB_Title = e. Item. FindControl ("LB_Title") as LinkButton;
Label LB_Id = e. Item. FindControl ("LB_Id") as Label;
LB_Title.CommandArgument = LB_Id.Text.ToString ();
}
}
Protected void Rep_Data_ItemCommand (object source, RepeaterCommandEventArgs e)
{
If (e. CommandName = "Display ")
{
Int index = Convert. ToInt32 (e. CommandArgument );
Business. Fig MyKLC = new Business. Fig ();
MyKLC = Business. Fig. GetModel (index );
This.txt. InnerHtml = MyKLC. MC_Text;
RegisterStartupScript ("", "<script type = 'text/javascript '> displays (); </script> ");
This. Pn_Display.Visible = true;
This. Pn_GridView.Visible = false;
}
}
To sum up, put two controls in Repeater. It seems that Repeater does not have the DataKeys attribute at the moment. Therefore, to transmit command parameters, only one control can be used for bearing. Other usage is similar to that of the GridView.
2. Generally, server controls and hyperlinks are not bound to Repeater,
<Asp: Repeater ID = "Rep_Data" runat = "server">
<ItemTemplate> <li> <a href = 'healthucationdisplay. aspx? Action = Display & Id = <% # Eval ("HE_Id") %> '> <% # Eval ("HE_Question ") %> </a> <span style = "float: right; height: 22px; line-height: 22px"> <% # Eval ("HE_CreateDate ") %> </span> </li>
</ItemTemplate>
</Asp: Repeater>
The style defined here can be completely defined in the CSS file of the project.
Then, in the pageload event, determine the input parameters and operations.
<ItemTemplate> <li> <a href = 'healthucationdisplay. aspx? Action = Display & Id = <% # Eval ("HE_Id") %> '> <% # Xkzi. common. utils. stringPlus. clipString (Eval ("HE_Question", "{0}"), 11) %> </a> <span style = "float: right; height: 22px; line-height: 22px "> <% # DateTime. parse (Eval ("HE_CreateDate", "{0 }")). toString ("yyyy-MM-dd") %> </span> </li>
Another common binding method