Dynamic Ordered list using Repeater in Asp .Net

 In this article we will see how to create dynamic Ordered list using repeater and datatable (You can also use database).With this technique we can also easily create dynamic menus in asp .net. Ordered lists use <ol></ol> and <li></li> tags to create Ordered lists so we will use same tags within repeater to create our Ordered list.

Step1: Create Method to add some data into datatable. This method will return Datatable.(NameSpace Required Using System.Data)

 

 public DataTable createDataTable()
    {
        DataTable dt = new DataTable();
        DataColumn dc = new DataColumn();
        dc.ColumnName = "Name";
        dc.DataType = typeof(string);

        dt.Columns.Add(dc);

        dt.Rows.Add(new object[] { "Asp .Net Examples" });
        dt.Rows.Add(new object[] { "Repeater Examples" });
        dt.Rows.Add(new object[] { "GridView Examples" });
        dt.Rows.Add(new object[] { "Validation Examples" });
        dt.Rows.Add(new object[] { ".Net Interview Questions" });
        dt.Rows.Add(new object[] { "Listview Examples" });
        dt.Rows.Add(new object[] { "Validation Summary Examples" });
        dt.Rows.Add(new object[] { "AjaxControlToolKit Examples" });
        dt.Rows.Add(new object[] { "ModalPopup Examples" });
        dt.Rows.Add(new object[] { ".Net Practice Questions" });

        return dt;

    }


Step2: Create Repeater Control

  1. <%#Eval("Name") %>

Step3: Create Method to bind repeater with datatable data.

 

 public void createUnorderedListUsingRepeater()
    {
        repOrderedList.DataSource = createDataTable();
        repOrderedList.DataBind();
    }

Step4: Call method from Page_Load() to bind repeater with data.

 

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            createUnorderedListUsingRepeater();
        }
    }
Final Output: Ordered-List-using-Repeater-asp-net-codingfusion

 
About Us | Terms of Use | Privacy Policy | Disclaimer | Contact Us Copyright © 2012-2024 CodingFusion
50+ C# Programs for beginners to practice