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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Aug 14, 2013, 2:45 AM EDT
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();
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Aug 14, 2013, 1:53 AM EDT
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.
Parthiban B49 reputationPosted Aug 14, 2013, 2:36 AM EDT