DataGrid Noob

liunx

Guest
Ok, i've developed using .NET before, but it wasn't for web applications. I am using ASP currently but we need to use a datagrid. I've searched and found nothing on Classic ASP Datagrids, so I'm assuming i have to use .NET. Below is the sample code that i'm using and need to figure out how to migrate it into the datagrid. Right now I have one page in the folder that is named tabletest.aspx.

Set Conn1 = Server.CreateObject("ADODB.Connection")
Conn1.Open GetConnStr(Session("DB"))

Set RS = Conn1.Execute("SELECT * FROM Table")



Any information is greatly appreciated.

Thanks,
Joshif you google it, there should be alot of examples out there. but the basic idea is to load your datasource, and then bind it with your datagrid control.

so at ur aspx page, drop a datagrid to your perfered position. give itself a name (i.e. dg1).

go to your code-behind, and start binding ur datagrid:


private string connectionString = "(your connection string goes here)";

private void Page_Load(Object sender, EventArgs e){
string Sql = "SELECT * FROM Table");
OleDbConnection con = new OleDbConnection(connectionString);
OleDbCommand cmd = new OleDbCommand(Sql, con);
OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
con.Open();
adapter.Fill(ds, "Table");
con.Close();
dg1.DataSource = ds;
dg1.AutoGenerateColumns = true;
dg1.DataBind();
}//end page_Load
 
Back
Top