如何在按钮单击事件上从 DataGridView 填充文本框
我想从 DataGridView 控件填充按钮单击事件的数据:
我的代码如下
for (int i = 0; i < dgv_EmpAttList.Columns.Count; i++)
{
txt_EnrollNo.Text = this.dgv_EmpAttList.CurrentRow.Cells[i].Value.ToString();
txt_FirstInTime.Text = this.dgv_EmpAttList.CurrentRow.Cells[i].Value.ToString();
txt_LastOutTime.Text = this.dgv_EmpAttList.CurrentRow.Cells[i].Value.ToString();
txt_TotalHours.Text = this.dgv_EmpAttList.CurrentRow.Cells[i].Value.ToString();
}
I want to fill data on button click event from DataGridView Control:
My code like this
for (int i = 0; i < dgv_EmpAttList.Columns.Count; i++)
{
txt_EnrollNo.Text = this.dgv_EmpAttList.CurrentRow.Cells[i].Value.ToString();
txt_FirstInTime.Text = this.dgv_EmpAttList.CurrentRow.Cells[i].Value.ToString();
txt_LastOutTime.Text = this.dgv_EmpAttList.CurrentRow.Cells[i].Value.ToString();
txt_TotalHours.Text = this.dgv_EmpAttList.CurrentRow.Cells[i].Value.ToString();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
循环浏览您的列可能不会有帮助。
尝试为每个文本框分配它映射到的单元格:
Looping through your columns probably won't help here.
Try assigning each textbox the cell that it is mapped to:
为什么必须使用循环?只需编写
编辑:
然后在按钮上单击发送行以更新并编写代码如下
Why you have to use looping? Simply you can write
EDIT:
Then on Button click send the row to update and write the code as follows