当我运行它没有显示任何内容并且没有出现错误时,我正在绑定gridview中的数据 [英] i'm binding the data from gridview when i run its shows nothing and no error appear
本文介绍了当我运行它没有显示任何内容并且没有出现错误时,我正在绑定gridview中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
binddata();
}
}
private void binddata()
{
string connstring = @"Data Source=LENOVO-41B3F2CE\SQLEXPRESS;Initial Catalog=IMS;Integrated Security=True;Pooling=False";
string query = "SELECT * FROM ['ISB VAS Nodes$']";
SqlDataAdapter da = new SqlDataAdapter(query, connstring);
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
推荐答案
'];
SqlDataAdapter da = new SqlDataAdapter(query,connstring);
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
']"; SqlDataAdapter da = new SqlDataAdapter(query, connstring); DataTable dt = new DataTable(); da.Fill(dt); GridView1.DataSource = dt; GridView1.DataBind(); }
调试代码并检查DataTable dt
中的行数。这是因为有DataTable
中的行没有你的gridview绑定但没有显示任何记录。
--Amit
Debug your code and check the number of rows inDataTable dt
. It''s because there is no rows in theDataTable
your gridview is binding but not showing any records.
--Amit
使用DataAdapter时遵循以下步骤:
1)打开连接
2)创建DataAdapter
3)使用DataAdapter填写表格
4)将表格绑定到GridView
参考以下链接: http://www.dotnetperls.com/sqldataadapter [ ^ ]
如果遵循以上步骤,请确保AutoGenerateColumns
属性GridView的设置为TRUE
,或者您需要定义gridview的每一列。我认为使用这些步骤可以看到GridView。如果不是,请回复。
While using DataAdapter following steps are followed:
1) Open a connection
2) Create a DataAdapter
3) Fill a table using DataAdapter
4) Bind table to GridView
Reference from below link:http://www.dotnetperls.com/sqldataadapter[^]
If above steps are followed, ensure the"AutoGenerateColumns"
property of GridView is set toTRUE
or you will need to define each column of the gridview. I think GridView should be visible using these steps. Please reply back if otherwise.
这篇关于当我运行它没有显示任何内容并且没有出现错误时,我正在绑定gridview中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文