Click here to Skip to main content
12,823,984 members (47,728 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET
i want to bind data to gridview how should i do it......
Posted 20-Nov-12 1:20am
faisal23 20-Nov-12 6:25am
There are 2 ways to bind data to gv but in both you require datasource. Either by design or coding.
Member 9579525 20-Nov-12 6:27am
thank u....can u suggest me code

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

protected void Page_Load(object sender, EventArgs e)
if (!Page.IsPostBack)
string connectionString = “server=SYS2;” + “integrated security=SSPI;” +
SqlConnection myConnection;
string str_Account_Select = “SELECT * FROM AccountsTable”;
SqlCommand myCommand;
DataSet myDataSet;
myConnection = new SqlConnection(connectionString);
myCommand = new SqlCommand(str_Account_Select, myConnection);
SqlDataAdapter mySQLDataAdapter;
myDataSet = new DataSet();
mySQLDataAdapter = new SqlDataAdapter(myCommand);
mySQLDataAdapter.Fill(myDataSet, “AccountsTable”);
GridView1.DataSource = myDataSet;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170308.1 | Last Updated 20 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100