Click here to Skip to main content
15,917,793 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to bind data for grid view on button click

and also display the table data in the grid view...

But i do not know the code to be written for this Asp.net and ms sql server 2005

plz tell me in steps what to do....
Posted
Comments
Herman<T>.Instance 18-Sep-12 3:17am    
what have you tried so far? We are here to help but not to programm your work

1 solution

Hi Rathi,,

Please try like below code.


C#
Using(SqlConnection con=new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["master"].ConnectionString))
        {
            con.Open();
            SqlCommand cmd = new SqlCommand("select  *  from userinfo ", con);
            DataTable dt = new DataTable();
            SqlDataAdapter adpt = new SqlDataAdapter(cmd);
            adpt.Fill(dt);
            GridView1.DataSource = null;
            GridView1.DataSource = dt;
            GridView1.DataBind();
}



It may be help u
 
Share this answer
 
v2
Comments
[no name] 18-Sep-12 3:20am    
or use entity framework to directly do it in the design page....

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900