如何将数据集绑定到Gridview [英] How to bind dataset to Gridview

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

问题描述

大家好,
我有一点疑问
我的数据集包含三个字段,例如:ID,NAME和Points

我必须将此数据集绑定到Gridview.我的问题是我只需要向最终用户显示两个字段(NAME和Points).在这种情况下可以将数据集绑定到Gridview吗?
谢谢.

Hi All,
I have got small doubt
My dataset has three fields like: ID, NAME, and Points

I have to bind this dataset to Gridview. My problem is that I have to display only two fields to the end user (NAME and Points). Can I bind my dataset to the Gridview in this scenario????

Thanks

推荐答案

当然,只需将ID列的可见性设置为false.
Sure, just set visibility for the ID-column to false.


SqlDataAdapter adap = new SqlDataAdapter("select * from tablename,con);
con.Open();
DataSet ds = new DataSet();
adap.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();

在设计视图中用作:
< asp:gridview id ="GridView1" autogeneratecolumns ="false" runat ="server">
<列> < asp:boundfield datafield ="NAME"标头文字="NAME">
< asp:boundfield datafield ="Points" headertext ="Points">
SqlDataAdapter adap = new SqlDataAdapter("select * from tablename", con);
con.Open();
DataSet ds = new DataSet();
adap.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();

and in design view use as:
<asp:gridview id="GridView1" autogeneratecolumns="false" runat="server" >
<columns> <asp:boundfield datafield="NAME" headertext="NAME">
<asp:boundfield datafield="Points" headertext="Points">


嗨.
选择ID列,然后看到= false.
或者您可以使用:

Hi.
select ID column and then visible = false.
or you can use of:

dataGridView1.Columns["id"].Visible = false;


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

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