Monday, February 25, 2008

Asp.Net DataList Part I

DataList is a templated control. You specify how to display the items, alternating items, Header, Footer etc. using , etc.

First let's see how to a simple DataList Example:
Instead of hard coding the connection string information I am using the section of web.config to specify the connection string information.

//web.config




















using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
SqlConnection cnn;
SqlDataAdapter da;
DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
cnn = new SqlConnection(ConfigurationManager.AppSettings.Get("Cnn"));
da = new SqlDataAdapter("select * from Categories", cnn);
da.Fill(ds, "Cat");
DataList1.DataSource = ds.Tables["Cat"];
DataBind();
}
}

























































Creating a custom table with DataList































Output

















DataList HyperLink Template - Asp.Net DataList - II

Happy Programming
shalvin@gmail.com

No comments:

Post a Comment