Sunday, January 17, 2010

using DataList Control

HTML Part

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





Untitled Page




Course Id Course Name Course Duration Course Fees

>

>

>

>




*****************************************
C# part-
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