Use a Repeater instance

Source: Internet
Author: User

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

 

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.