如何在asp.net窗口应用程序中的文本框和gridview中的文本框中显示数据 [英] how to display data in text box and the text box in gridview in asp.net window application
本文介绍了如何在asp.net窗口应用程序中的文本框和gridview中的文本框中显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public void loadToinletProduct( string id)
{
Connection objC1 = new Connection();
SqlDataAdapter adp;
DataSet ds = new DataSet();
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = select * from tblstudent其中stuid = + ID;
cmd.CommandType = CommandType.Text;
cmd.Connection = objC1.objCon;
尝试
{
objC1.objCon.Open();
adp = new SqlDataAdapter(cmd);
adp.Fill(ds);
dt = ds.Tables [ 0 ];
// 设置AutoGenerateColumns False
dataGridView2.AutoGenerateColumns = < span class =code-keyword> false ;
// 设置列数
// dataGridView1.Refresh();
dataGridView2.ColumnCount = 7 跨度>;
// //添加列
// dataGridView2.Columns [0] .Name =productName;
// dataGridView2.Columns [0] .HeaderText =Product;
// dataGridView2.Columns [0] .DataPropertyName =productName;
显示哪些代码 in gridview in textbox
dataGridView2.DataSource = dt;
}
catch (例外ei)
{
MessageBox.Show(ei.Message);
}
最后
{
objC1.objCon.Close();
}
}
解决方案
参考:
动态地将BoundField和TemplateField列添加到ASP.Net中的GridView [ ^ ]
public void loadToinletProduct(string id)
{
Connection objC1 = new Connection();
SqlDataAdapter adp;
DataSet ds = new DataSet();
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from tblstudent where stuid=" + id;
cmd.CommandType = CommandType.Text;
cmd.Connection = objC1.objCon;
try
{
objC1.objCon.Open();
adp = new SqlDataAdapter(cmd);
adp.Fill(ds);
dt = ds.Tables[0];
//Set AutoGenerateColumns False
dataGridView2.AutoGenerateColumns = false;
//Set Columns Count
//dataGridView1.Refresh();
dataGridView2.ColumnCount = 7;
// //Add Columns
//dataGridView2.Columns[0].Name = "productName";
//dataGridView2.Columns[0].HeaderText = "Product";
//dataGridView2.Columns[0].DataPropertyName = "productName";
which code to display in gridview in textbox
dataGridView2.DataSource = dt;
}
catch (Exception ei)
{
MessageBox.Show(ei.Message);
}
finally
{
objC1.objCon.Close();
}
}
解决方案
refer:
Dynamically add BoundField and TemplateField Columns to GridView in ASP.Net[^]
这篇关于如何在asp.net窗口应用程序中的文本框和gridview中的文本框中显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文