单击Button时显示datagrid。 [英] Display datagrid when a Button is clicked.
本文介绍了单击Button时显示datagrid。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个已绑定到数据库的数据网格。
如何在单击按钮时在数据网格上显示数据?
I have a datagrid which is already binded to a DB.
how to display data on the datagrid when a button is clicked ?
推荐答案
在按钮点击事件中
SqlDataAdapter adp = null;
DataSet ds = null;
试试
{
adp = new SqlDataAdapter(你的查询,连接字符串);
adp.SelectCommand.CommandTimeout = 100000;
ds = new DataSet();
adp.Fill(ds);
DataGridview.DataSource = ds;
//对于Web应用程序再添加一行
DataGridview.DataBind();
}
catch(SqlException ex)
{
throw;
}
Hi,
In the button click event
SqlDataAdapter adp = null;
DataSet ds = null;
try
{
adp = new SqlDataAdapter("your query", connection string);
adp.SelectCommand.CommandTimeout = 100000;
ds = new DataSet();
adp.Fill(ds);
DataGridview.DataSource=ds;
//For Web application add one more line
DataGridview.DataBind();
}
catch (SqlException ex)
{
throw;
}
U can bind ur DB TO datagrid, into the button click event.
private void btn_Click(object sender, EventArgs e)
{
String Query=Select * from UrTableName"
SqlDataAdapter DA=new SqlDataAdapter(Query,UrConnectionStringName);
DataSet DS=new DataSet();
DA.fill(DS);
URDATAGRIDVIEWNAME.datasource=ds;
}
这篇关于单击Button时显示datagrid。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文