gridview响应双击 [英] gridview responding to double click
问题描述
我有一个既具有文本框又具有gridview的表单.当从组合框中选择一个工作人员编号时,Gridview将显示有关该工作人员的所有交易记录.每个员工都有一笔以上的交易.我希望girdview在双击该行时将特定行中的记录显示到各自的文本框中.
我对此感到厌倦,但在文本框中甚至会持续显示一条特定记录
如果选择了另一行.我如何修改我的sql语句以根据组合框中的staffid和gridview中的tansactionid进行选择?
请帮帮我
i have a form which has both textboxes and a gridview. when a staffid is selected from the combo box, the gridview displays all the transactional records about the staff. each staff have got more than one transaction. i want the girdview to display the records in a particular row into their respective textboxes when that row is double - clicked.
i tired this but one particular record keeps on displaying in the text boxes even
if a different row is selected. how do i modify my sql statement to select based on the staffid in the combo box and the tansactionid in the gridview?
pls help me out
private void dgvStaffsalarypayment_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
conn.ConnectionString = "Data Source=MICKY-PC;Initial Catalog=SMS;User ID=sa;Password=mike";
conn.Open();
SqlCommand cmd = new SqlCommand();
string sqlQuery = dgvStaffsalarypayment[0, e.RowIndex].Value.ToString();
sqlQuery = "select * from tblstaffsalarypaymentdetails where staffid like '" + this.cboStaffid5.Text + "%" + "'";
cmd.Connection = conn;
cmd.CommandText = sqlQuery;
cmd.CommandType = System.Data.CommandType.Text;
SqlDataReader dr = null;
dr = cmd.ExecuteReader();
while (dr.Read())
{
cboStaffid5.Text = dr["staffid"].ToString();
dtpDateofpayment.Text = dr["dateofpayment"].ToString();
cboPurpose.Text = dr["purpose"].ToString();
cboYear.Text = dr["years"].ToString();
cboMonth.Text = dr["months"].ToString();
txtAmountpaid.Text = dr["amountpaid"].ToString();
txtRemarks.Text = dr["remarks"].ToString();
}
cmd.Dispose();
}
推荐答案
这是解决方案.感谢Wes Aday
this is the solution. thanks to Wes Aday
select * from tblstaffsalarypaymentdetails where staffid like '" + this.cboStaffid5.Text + "%" + "' AND staffsalarytransid like '" + this.dgvStaffsalarypayment.Rows[e.RowIndex].Cells[0].Value + "%" + "'
这篇关于gridview响应双击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!