Guide for Asp gridview bind function
guide me for asp.net gridview bind() from SQL table
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sanjeeb LenkaPosted Aug 14, 2013, 6:45 AM
in aspx page:
in cs:
add the namespaces:
using System.Data.SqlClient;
using System.Data;
write this code in page load:
string connstr = "Data Source=WIN2K8; Initial Catalog=ABC;User ID=sa; Password=123";
DataSet ds = new DataSet();
SqlConnection conn = new SqlConnection(connstr);
string strsql = "Select StudentID,StudentName from student";
SqlDataAdapter da = new SqlDataAdapter(strsql, conn);
da.Fill(ds, "student");
grid.DataSource = ds.Tables["student"];
grid.DataBind();
Parthiban BPosted Aug 14, 2013, 6:36 AM
Sanjeeb LenkaPosted Aug 14, 2013, 5:53 AM
Launch Visual Studio 2010, click on File->New->Website to create a new ASP.NET website Project.
Step 2: Create a new Page
Right click on the Project on the Solution Explorer Panel. Select Add->New Item. Then, choose Web Form. I'd like to name it Products.aspx
Step3: Add the following code to the Products.aspx file
then go to .cs and
add the namespaces:
using System.Data.SqlClient;
using System.Data;
write this code in page load:
string connstr = "Data Source=WIN2K8; Initial Catalog=ABC;User ID=sa; Password=123";
DataSet ds = new DataSet();
SqlConnection conn = new SqlConnection(connstr);
string strsql = "Select * from Products";
SqlDataAdapter da = new SqlDataAdapter(strsql, conn);
da.Fill(ds, "ProductsTable");
grid.DataSource = ds.Tables["ProductsTable"];
grid.DataBind();
change the connection string as your and change the query and check.