Tuesday, October 16, 2012

PagingBulletedListExtender Example

 

Sample Example using PagingBulletedListExtender

<form id="form1" runat="server">
    <div>
        <ajaxToolkit:ToolkitScriptManager ID="Sc1" runat="server">
        </ajaxToolkit:ToolkitScriptManager>
        <asp:BulletedList ID="BulletedList1" runat="server">
        <asp:ListItem Text="Assam" Value="1"></asp:ListItem>
        <asp:ListItem Text="Bihar" Value="2"></asp:ListItem>
        <asp:ListItem Text="Chennai" Value="3"></asp:ListItem>
        <asp:ListItem Text="Delhi" Value="4"></asp:ListItem>
        <asp:ListItem Text="Japan" Value="5"></asp:ListItem>
        <asp:ListItem Text="Rajasthan" Value="6"></asp:ListItem>       
        </asp:BulletedList>
        <ajaxToolkit:PagingBulletedListExtender ID="PagingBulletedListExtender1"
             runat="server" TargetControlID="BulletedList1">
        </ajaxToolkit:PagingBulletedListExtender>
    </div>
    </form>

Output

paging BulletExtender1          Paging bulleted 2

“PagingBulletedListExtender” Example which fetches list of state names from the database and displays it in alphabetical order with paging .

Aspx Code:

<form id="form1" runat="server">
   <div>
       <ajaxToolkit:ToolkitScriptManager ID="Sc1" runat="server">
       </ajaxToolkit:ToolkitScriptManager>
       <asp:BulletedList ID="BulletedList1" runat="server"
           DataTextField="state_descp" DataValueField="state_cd">
       </asp:BulletedList>
       <ajaxToolkit:PagingBulletedListExtender ID="PagingBulletedListExtender1"
            runat="server" TargetControlID="BulletedList1">
       </ajaxToolkit:PagingBulletedListExtender>
   </div>
   </form>

Code Behind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

public partial class Ajax_Controls_Examples_PagingBulletedListExtender : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        GetData();
    }
    protected void GetData()
    {
        DataTable DtStates = new DataTable();
        SqlConnection Con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConString"].ToString());
        Con.Open();

        SqlCommand Cmd = new SqlCommand("Get_StateCodes" , Con);
        Cmd.CommandType = CommandType.StoredProcedure;

        SqlDataAdapter Adp = new SqlDataAdapter(Cmd);
        Adp.Fill(DtStates);

        BulletedList1.DataSource = DtStates;
        BulletedList1.DataBind();

    }
}

Output :

Paging Bulleted 3              PagingBulleted 4

No comments:

Post a Comment