Resources » Code Snippets » ASP.NET WebForms

Bulleted List


Posted Date: 15-Sep-2009  Last Updated:   Category: ASP.NET WebForms    
Author: Member Level: Gold    Points: 5



Bulleted list



Description:

The below code is used to bind the bulleted list with
i) Hash tabe
2) Array list
3) Database Table
4) XML File
And while clicking on the bulleted list, it displays the text you clicked.

Design:


< form id="form1" runat="server" >
< div class="style1" >
< h5 >< font color='Brown'>Binding Bulleted list with Hash table< /font >< /h5 >
< asp:BulletedList ID="BltSample" runat="server"
DataTextField="Value" DataValueField="Key" onclick="BltSample_Click1" DisplayMode="LinkButton" >
< /asp:BulletedList >
< asp:Label ID="Label1" runat="server" >< /asp:Label >
< h5 >< font color='Brown'>Binding Bulleted list with Array list< /font > < /h5 >
< asp:BulletedList ID="Blt2" runat="server >
< /asp:BulletedList >
< h5 >< font color='Brown' >Binding Bulleted list with Database table< /font >< /h5 >
< asp:BulletedList ID="BltListDb" runat="server" >
< /asp:BulletedList >
< h5 >< font color='red' >Binding Bulleted list with XML file< /font >< /h5 >
< asp:BulletedList ID="BltListXml" runat="server" DataSourceID="BindXMlyoBulltedlist" DataTextField="Title" DataValueField="idmain" >
< /asp:BulletedList >

< asp:XmlDataSource ID="BindXMlyoBulltedlist" runat="server"
DataFile="~/Categories.xml" >< /asp:XmlDataSourc >
< /div >
< /form >


Code Behind:



string sCon = ConfigurationSettings.AppSettings["Con"].ToString();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Bind();
}
}

private void Bind()
{

//Binding Bulleted list using hash table

Hashtable ht = new Hashtable();
ht.Add("1", "First");
ht.Add("2", "Second");
ht.Add("3", "Third");
ht.Add("4", "Fourth");
ht.Add("5", "Five");
BltSample.DataSource = ht;
BltSample.DataBind();


// Simple binding to Bulleted list

for (int i = 0; i < 10; i++)
{
BltSample.Items.Add(i.ToString());
}


//Binding with Arraylist

ArrayList arr = new ArrayList();
arr.Add(1);
arr.Add(2);
arr.Add(3);
Blt2.DataSource = arr;
Blt2.DataBind();


//Binding with database table

DataSet ds = SqlHelper.ExecuteDataset(sCon, "PS_WFM_Category_Get");

if (ds.Tables.Count > 0)
{
if (ds.Tables[0].Rows.Count > 0)
{
BltListDb.DataSource = ds.Tables[0];
BltListDb.DataTextField = "CategoryName";
BltListDb.DataValueField = "CategoryId";
BltListDb.DataBind();
}
}

}

protected void BltSample_Click1(object sender, BulletedListEventArgs e)
{


//Displaying text on label when clicking on bulleted list item

Label1.Text = "< b >Total number of items in the list are:< /b > " + BltSample.Items.Count + "< br >" + "< b >Selected Item is: < /b >"+ BltSample.Items[e.Index].Text.ToString();

}


XML File:


< ?xml version="1.0" encoding="utf-8" ? >

< Category >
< CategoryType idmain="1" Title="XML Tutorial" >
< /CategoryType >
< CategoryType idmain="2" Title="XML Samples" >
< /CategoryType >
< CategoryType idmain="3" Title="XML Questions" >
< /CategoryType >
< /Category >

Attachments


Page1


Did you like this resource? Share it with your friends and show your love!

Responses to "Bulleted List"

No responses found. Be the first to respond...

Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Submit Article     Return to Article Index

    Subscribe to Subscribers
    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Talk to Webmaster Tony John

    Online Members

    Pawan Awasthi
    More...
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India