如何使用gridview中的复选框更新文本框文本 [英] how to use the checkbox in gridview to update a textbox text
本文介绍了如何使用gridview中的复选框更新文本框文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个gridview,其中列出了用户信息,我添加了一个复选框字段。
取决于复选框值文本字段数据更新,即如果我选择第一个复选框,用户名对此该行的复选框列在文本框中,当我选择多个复选框时,所有用户名都应该显示在那里。
请告诉我该怎么做
谢谢
解决方案
这应该可以让您大致了解该怎么做。
这是我与访问数据库一起使用的代码,用于选择与所选Datagridview行相关的文本框中的特定数据。
private void DGReview_CellClick( object sender,DataGridViewCellEventArgs e)
{
conn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd = conn.CreateCommand();
cmd.CommandText = @ SELECT * FROM [Table] WHERE [Variable] =' + DGReview.SelectedRows [ 0 ]。单元格[ 0 ]。Value.ToString()+ ';
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
OleDbDataAdapter adapterA = new OleDbDataAdapter();
adapterA.SelectCommand = cmd;
adapterA.Fill(dt);
对象 a = dt.Rows [ 0 ] [ 变量];
textbox.Text = Convert.ToString(a);
conn.Close();
}
方法在哪里DG_Review_CellClick你的可能是checkbox_CheckedChanged
i have a gridview in which user info is listed and i have added a checkbox field.
depending on the checkbox value the textfield data is updated i.e. if i select the first checkbox the username against this checkbox of that row is listed in the textbox and when i select multiple checkboxes then all the username should display there.
Please tell me how to do that
thanks
解决方案
This should give you a rough idea of what to do.
This is code I have used with an access db to select specific data into text boxes related to the selected Datagridview row.
private void DGReview_CellClick(object sender, DataGridViewCellEventArgs e) { conn.Open(); OleDbCommand cmd = new OleDbCommand(); cmd = conn.CreateCommand(); cmd.CommandText = @"SELECT * FROM [Table] WHERE [Variable] ='" + DGReview.SelectedRows[0].Cells[0].Value.ToString() + "'"; cmd.ExecuteNonQuery(); DataTable dt = new DataTable(); OleDbDataAdapter adapterA = new OleDbDataAdapter(); adapterA.SelectCommand = cmd; adapterA.Fill(dt); Object a = dt.Rows[0]["Variable"]; textbox.Text = Convert.ToString(a); conn.Close(); }
Where as the method is DG_Review_CellClick yours would probably be checkbox_CheckedChanged
这篇关于如何使用gridview中的复选框更新文本框文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文