Data Binding

So what is data binding? It’s a technique to fill a Asp Control with values from a source. This source could be an XML, or a database. Why would you want that? To create dynamic websites of course!
With data binding techniques, you can separate the way you make data visible, and the actual data.
More posts about this, you can find by tag.

Possibilities for the different Data Bind Controls

Repeater DataList GridView
Templates X X
Styles X
Columns X
Select Items X

Templates

Yes, to show the items from the collection or datasource, we will use templates. This is how we transform the data, to for example, a link. Every Control in the Data Controls, has his own set of templates it can use. What each template does, and wich control use them, you can see in the table below:

Repeater Control DataList Control
HeaderTemplate X X Text above all the items
ItemTemplate X X Each item
AlternatingItemTemplate X X
SeparatorTemplate X X Between items.
FooterTemplate X X At the end of the collection.
SelectedItemTemplate X

Styles

Styles help you with the layout, the colours. What kind of styles are there? A list:

  • ItemStyle
  • AlternatingItemStyle
  • SeparatorStyle
  • HeaderStyle
  • FooterStyle
  • SelectedItemStyle
  • EditItemStyle

Add hyperlink to the Bulleted List Control

This will be a very short tutorial, but still I couldn’t find any information relevant to the search: How to add hyper link to the bulleted list control.

Nevertheless this is pretty easy. We assume you want to do this in your Code-behind File, so you can add hyperlink in a list dynamically.

First create the BulletedList control, then you have to set his mode to hyperlink.

BulletedList BL = new BulletedList();
BL.DisplayMode = BulletedListDisplayMode.HyperLink;

Now that we have the control,the next code is how to add the hyperlinks. I will show how to add one. With a simple iteration you can add more, the way you might want it.

item.Text = "The text of the link";
item.Value = "the-url.aspx";
BL.Items.Add(item);

Good luck with your project!

Add items to the Bulleted List Control (in the code file)

My next tutorial will be a really short one. But still I have spent a really long time to find what I was looking. Maybe because it was way to easy?

I wanted to generate a BulletedList Web Control, in my code file. Inside a for-loop I wanted to add texts to my list.

[ad#Adsense]

To start, I dropped a PlaceHolder in my file.asp (The html file). Because I like drag and drop, I did it that way! You can find in your toolbox. If you don’t like that, just copy-paste the following text where you would like your BulletedList to appear:
<asp:PlaceHolder ID="ph1" runat="server"></asp:PlaceHolder>
After that it is time to open the code behind file. In the solution explorer, click at the plus, and then open the default.aspx.cs!

The first thing is to make our Place Holder accessible. Just behind:
public partial class Default: System.Web.UI.Page
But above:
protected void Page_Load(object sender, EventArgs e)
We type this code:
private PlaceHolder PH
{
get
{
return ph1;
}
set
{
ph1 = value;
}
}

We have to create the BulletedList outside the iterator. And inside we can add the items we want to the BulletedList. First my example:
BulletedList BltTest = new BulletedList();
foreach (XmlNode QuestionAnswers in Question)
{
BltTest.Items.Add(new ListItem(QuestionAnswers.InnerText));
}
PH.Controls.Add(BltQTest);

This is the code I did use. But maybe a more generic example helps you with your BulletedList problem!
BulletedList BltTest = new BulletedList();
for (int i = 0; i < 10; i++)
{
BltTest.Items.Add(new ListItem("This is the " + i + "th item"));
}
PH.Controls.Add(BltQTest);

Good luck with your BulletedList!