.net框架中Windows应用程序的datagridview控件 [英] datagridview control of windows application in .net framework
本文介绍了.net框架中Windows应用程序的datagridview控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们如何在datagridview控件中动态添加控件,例如在文本框之类的垂直列中,我还希望从数据库中使用这些控件的值,还希望对lostfocus事件进行一些运算,并且还具有一个页脚行来添加垂直列所有值.(仅在Windows应用程序中,不在Web应用程序中).
how we dynamically add control in datagridview control like in a perticular column like textbox and i also want values from database which use these control and also want to to calculate some operation on lostfocus event and it also has a footer row which add perticular column all values.(In windows application only not in web application).
推荐答案
右键单击GridView,选择编辑列".
U将找到模板",添加模板字段.
在模板字段U中,可以拖动文本框,按钮,单选按钮,复选框.
对于向网格中添加一些值/行,只需将数据插入数据库并重新绑定网格即可.下面是绑定网格的代码;).
Right Click on GridView select Edit Column.
U will find "Template" , Add Template Field.
In template Field U can Drag Textbox,Button, RadioButton,CheckBox.
For Adding some value/row to Grid, just insert a data into database and rebind the Grid. Below is the code for binding the grid ;) .
public void LoadGrid()
{
DataTable dt = new DataTable();
sqlcon = new SqlConnection(con );
sqlcon.Open();
SqlDataAdapter sda = new SqlDataAdapter();
string strQuery = "select * from employee ";
SqlCommand cmd = new SqlCommand(strQuery);
cmd.CommandType = CommandType.Text;
cmd.Connection = sqlcon;
sda.SelectCommand = cmd;
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
希望这足以解决您的问题
Hope this is enough to solve ur problem
这篇关于.net框架中Windows应用程序的datagridview控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文