Search This Blog

2010/01/17

DataList Control:

HTML Part:
DataList Control:
HTML Part

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="DataList1" runat="server" OnSelectedIndexChanged="DataList1_SelectedIndexChanged" >
<HeaderTemplate>
<table>
<tr>
<td>Course Id</td>
<td>Course Name</td>
<td>Course Duration</td>
<td>Course Fees</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="LblCourseId" runat="server" Text=<%#DataBinder.Eval(Container.DataItem,"cno")%> ></asp:Label>
</td>
<td>
<asp:Label ID="LblCourseName" runat="server" Text=<%#DataBinder.Eval(Container.DataItem,"cname")%> ></asp:Label>
</td>
<td>
<asp:Label ID="LblCourseDuration" runat="server" Text=<%#DataBinder.Eval(Container.DataItem,"duration")%> ></asp:Label>
</td>
<td>
<asp:Label ID="LblCourseFees" runat="server" Text=<%#DataBinder.Eval(Container.DataItem,"fees")%> ></asp:Label>
</td>
</tr>
</ItemTemplate>

<FooterTemplate>

</table>
</FooterTemplate>
</asp:DataList></div>
</form>
</body>
</html>


*********************************************************************************
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{
if (! Page.IsPostBack)
{
SqlConnection con = new SqlConnection("Initial Catalog=sangram;Integrated Security=SSPI;Data Source=(local);");
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from courses", con);
ds= new DataSet();
da.Fill(ds, "courses");
DataTable dt = new DataTable();
dt = ds.Tables[0];
DataList1.DataSource = dt;
DataList1.DataBind();




}

}
protected void DataList1_SelectedIndexChanged(object sender, EventArgs e)
{


}
}

No comments:

Post a Comment