如何获得按钮上的数据网格视图 [英] how to get data grid view on button

查看:67
本文介绍了如何获得按钮上的数据网格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用GUI表单,我在表单上放置了一个名为display的按钮.我希望当我单击该按钮时,数据网格视图将出现在屏幕上,其中包含表单数据,该表单数据通过数据库与数据库链接绑定源.

I am working on a GUI form and i put one button named display on form.I want that when i click on that button then the data grid view will appear on the screen which contained that forms data which is linked with database through binding source.

推荐答案

在按钮按键事件上选中此选项

check this on button keypress event

if(e.Keychar == (char)13)
{
    string strSQLconnection = "Data Source=dbServer;Initial Catalog=testDB;Integrated Security=True";
    SqlConnection sqlConnection = new SqlConnection(strSQLconnection);
    SqlCommand sqlCommand = new SqlCommand("SELECT * FROM TABLENAME", sqlConnection);
    sqlConnection.Open();
 
    SqlDataReader reader = sqlCommand.ExecuteReader();
       
    GridView1.DataSource = reader;
    GridView1.DataBind();
    GridView1.Visible = true;
    GridView1.Focus();
}



希望对您有帮助

另请检查此链接以供参考

如何使用C#中的SQL语句填充DataGridView,GridView [ ^ ]



hope this will help you

Also check this link for reference

How to populate DataGridView, GridView with SQL statement in C#[^]


这篇关于如何获得按钮上的数据网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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