Data loading from SQL Server database at runtime

Unknown | 12:41 PM |

Firstly Add DataList Control in Design View.Then Change the html code of Datalist as follows:





Source Code:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
using System.Data.SqlClient;

public partial class dynamic : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("Data Source=ELWIN;Initial Catalog=sherin;Integrated Security=True");
public void display(string query)
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter(query, con);
DataTable dt = new DataTable();
da.Fill(dt);
DataView dv = new DataView(dt);
PagedDataSource objpag = new PagedDataSource();
objpag.DataSource = dv;
objpag.AllowPaging = true;
objpag.PageSize = 5;
DataList1.DataSource = objpag;
DataList1.DataBind();
con.Close();

}
public void check(object sender, System.Web.UI.WebControls.CommandEventArgs e)
{

if (Session["programid"] != null)
{
Session["programid"] = Session["programid"] + " or programid=" + e.CommandName;

}
else
{
Session["programid"] = e.CommandName;
}

string fg = Session["programid"].ToString();
Response.Redirect("shoppingcart.aspx");
}

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{

display("select * from addprogram2 ");
}

}
}


Output:



Category:

About http://dotnetvisual.blogspot.in/:
DOT NET TO ASP.NET is a web application framework marketed by Microsoft that programmers can use to build dynamic web sites, web applications and web services. It is part of Microsoft's .NET platform and is the successor to Microsoft's Active Server Pages (ASP) technology. ASP.NET is built on the Common Language Runtime, allowing programmers to write ASP.NET code using any Microsoft .NET language. create an application very easily ....