[英]How to Get select row data of gridview into dropdown list and textboxes
I have textbox controls and ddl in asp.我在asp中有文本框控件和ddl。 Net form .. Through which i am saving data and showing it on grid view.. Now i have to update data by selecting specific row in gridview and selected data should be loaded into text boxes and ddls... How to do this
Net form .. 通过它我保存数据并将其显示在网格视图上.. 现在我必须通过在 gridview 中选择特定行来更新数据,并且所选数据应加载到文本框和 ddls 中......如何执行此操作
You can use the codes below to get index of the selected column if required:如果需要,您可以使用以下代码获取所选列的索引:
int columnIndex = dataGridView.CurrentCell.ColumnIndex;
int rowIndex = dataGridView.CurrentCell.RowIndex;
SelectionChanged function can be used to detect any user selection and you can set the values to your textbox and ddl inside the function: SelectionChanged 函数可用于检测任何用户选择,您可以将值设置为您的文本框和函数内的 ddl:
private void gridView_SelectionChanged(object sender, EventArgs e)
{
if (gridView.SelectedRows.Count > 0)
{
int age = Convert.ToInt32(gridView.SelectedRows[0].Cells["Age"].Value.ToString());
string name = gridView.SelectedRows[0].Cells["Name"].Value.ToString();
txtName.Text = name;
ddlAgeList.Items.Insert(0,new ListItem(age.ToString()));// 0 is index of item
}
}
ClickEvent function is also an alternative, see below: ClickEvent 函数也是一种替代方法,见下文:
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
txtName.Text = row.Cells["Name"].Value.ToString();
var age = row.Cells["Age"].Value.ToString();
ddlAgeList.Items.Insert(0,new ListItem(age));// 0 is index of item
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.