如何在Gridview中进行数据绑定? [英] How to do Data Binding in Gridview?

查看:97
本文介绍了如何在Gridview中进行数据绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在单击按钮时为网格视图绑定数据

并在网格视图中显示表数据...

但是我不知道要为此Asp.net和ms sql server 2005编写的代码

请逐步告诉我该怎么做....

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....

推荐答案

Rathi ,,

请尝试以下代码.


Hi Rat,

Please try like below code.


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


这篇关于如何在Gridview中进行数据绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆