Some minor problems in the use of the Repeater control

Source: Internet
Author: User

The data used to display the list on the webpage is found to be more flexible than repeater, such as gridview and detailview. Therefore, we will summarize some of the situations we encountered recently and keep them for future reference, don't ask du Niang now...

You may find something wrong.

1. The Repeater control can be an array, for example, an instance array of a class.

1 // front-end Code 2 <asp: repeater id = "Repeater" runat = "server" 3 onitemcommand = "repeater_itemcommand"> 4 
1 // background Code 2 newsclass [] array = is. Business. newsclassbll. getfirstlevelclass (); 3 repeater. datasource = array; 4 repeater. databind ();

2. Use commondargument to pass parameters to the background, and process the corresponding commands for buttons in the control in the itemcommand event.

        protected void repeater_ItemCommand(object source, RepeaterCommandEventArgs e)        {            switch (e.CommandName)            {                case "edit":                    ((Panel)e.Item.FindControl("pnl_display")).Visible = false;                    ((Panel)e.Item.FindControl("pnl_edit")).Visible = true;                    break;                case "cancel":                    ((Panel)e.Item.FindControl("pnl_display")).Visible = true;                    ((Panel)e.Item.FindControl("pnl_edit")).Visible = false;                    break;                case "delete":                    try                    {                        IS.Business.NewsClassBLL.Delete(int.Parse(e.CommandArgument.ToString()));                        this.bindData();                    }                    catch (Exception ex)                    {                        Functions.AlertMsg(ex.Message, Page);                    }                    break;                case "update":                    string oldname = e.CommandArgument.ToString();                    string newname = ((TextBox)e.Item.FindControl("txtBigClassName")).Text;                    try                    {                        IS.Business.NewsClassBLL.RenameFirstLevelClassName(oldname, newname);                        this.bindData();                    }                    catch (Exception ex)                    {                        Functions.AlertMsg(ex.Message, Page);                    }                    break;                default:                    break;            }        }

3. Two panels are used to implement functions similar to local editing. It seems that it is better to use placeholder without generating additional HTML tags.

4. The bound class contains an instance of another class as its property member. It is used to bind an attribute of its property member:

<%#DataBinder.Eval(((IS.Model.Exhibition)Container.DataItem).Area,"Name") %>

5. Add a row number:

<%#Container.ItemIndex+1 %>

6. format some input variables. Take the time as an example:

<%#DataBinder.Eval(Container.DataItem,"StartTime","{0:yyyy-MM-dd}") %>


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: 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.