Support us .Net Basics C# SQL ASP.NET Aarvi MVC Slides C# Programs Subscribe Download

Bulleted list in asp.net - Part 28

Suggested Videos
Part 25 - ASP.NET ListBox control
Part 26 - ASP.NET CheckBoxList and ListBox real time example
Part 27 - ASP.NET RadioButtonList control

In this video we will discuss about BulletedList in asp.net. 

In ASP.NET there are several list controls, like
1. DropDownList
2. CheckBoxList
3. RadioButtonList
4. ListBox
5. BulletedList

Just like every other list control
1. BulletedList is also a collection of ListItem objects.
2. Items can be added to the BulletedList in the HTML source or in the code behind file
3. BulletedList like any other list control supports databinding. For example, BulletedList can be bound to a database table or an xml file



Properties of BulletedList
BulletStyle - This property, is used to customize the bullets style. If CustomImage is specified as the BulletStyle, then BulletImageURL, also needs to be specified.

<asp:BulletedList ID="CountriesBulletedList" runat="server" BulletStyle="Numbered">
    <asp:ListItem Text="India" Value="1"></asp:ListItem>
    <asp:ListItem Text="US" Value="2"></asp:ListItem>
    <asp:ListItem Text="UK" Value="3"></asp:ListItem>
    <asp:ListItem Text="France" Value="4"></asp:ListItem>
</asp:BulletedList>

FirstBulletNumber - The Number at which the ordered list starts.

DisplayMode - Can be Text, HyperLink or LinkButton. The default is Text



The following HTML, sets the DisplayMode="HyperLink". By default, the target page is displayed in the same browser window. Set the Target property of the BulletedList to _blank, to open the target page in it's own window. 
<asp:BulletedList ID="CountriesBulletedList" runat="server" 
    BulletStyle="Numbered" DisplayMode="HyperLink">
    <asp:ListItem Text="Google" Value="http://google.com"></asp:ListItem>
    <asp:ListItem Text="Youtube" Value="http://Youtube.com"></asp:ListItem>
    <asp:ListItem Text="Blogger" Value="http://Blooger.com"></asp:ListItem>
    <asp:ListItem Text="Gmail" Value="http://Gmail.com"></asp:ListItem>
</asp:BulletedList>

The following HTML, sets DisplayMode="LinkButton" and onclick="CountriesBulletedList_Click"
<asp:BulletedList ID="CountriesBulletedList" runat="server" 
    DisplayMode="LinkButton" onclick="CountriesBulletedList_Click">
    <asp:ListItem Text="Google" Value="1"></asp:ListItem>
    <asp:ListItem Text="Microsoft" Value="2"></asp:ListItem>
    <asp:ListItem Text="Dell" Value="3"></asp:ListItem>
    <asp:ListItem Text="IBM" Value="4"></asp:ListItem>
</asp:BulletedList>

Code behind code
protected void CountriesBulletedList_Click(object sender, BulletedListEventArgs e)
{
    ListItem li = CountriesBulletedList.Items[e.Index];
    Response.Write("Text = " + li.Text + "<br/>");
    Response.Write("Value = " + li.Value + "<br/>");
    Response.Write("Index = " + e.Index.ToString());
}

No comments:

Post a Comment

It would be great if you can help share these free resources