简体   繁体   English

如何将gridview的选择行数据获取到下拉列表和文本框中

[英]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.

相关问题 如何在C#中使gridview将所有检查的行数据放入另一种形式的文本框中? - How to get gridview all checked row data into textboxes of another form in C#? 选择gridview行时将gridview行数据传递到文本框 - Passing gridview row data to textboxes on selection of gridview row 如何在gridview行中查找所有文本框? - How to find all textboxes in a gridview row? 如何在GridView的文本框中获取用户值的值 - how to get value of users' values in textboxes in GridView 如何使用 mvvm 将 gridview 选定的行数据发送到另一个 window 与 wpf 中的文本框使用 mvvm - How to send gridview selected row data to another window with textboxes in wpf using mvvm 如何从嵌套在转发器中的gridview的文本框中获取数据? - How do I get the Data from the textboxes within the gridview, nested in the repeater? 如何获取 gridview 中下拉列表的选定值? - How to get selected value for dropdown list inside gridview? 如何从使用链接按钮的gridview行中填充多个文本框 - How to populate multiple textboxes from a row in gridview that uses a link button Asp.net Gridview:添加行时,GridView中的文本框没有数据 - Asp.net Gridview: when add row there is no data from textboxes in gridview 在gridview中获取特定数据行? - Get specific data row in gridview?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM