Datagrid视图文本框失去价值

时间:2015-10-09 15:15:46

标签: c# asp.net

我有一个数据网格视图,其中我已将所有单元格更改为文本框以允许批量更新。问题是用户的新输入值没有注册,而是单元格保持旧值。我教过它可能与回发问题有关,但无法想象它是因为页面加载中没有加载旧数据。我还认为文本框可能没有正确注册,因为它们是在没有ID但没有确定的情况下添加的。

此处将单元格更改为文本框。

foreach (GridViewRow row in GridView1.Rows)
{
    for (int i = 4; i < row.Cells.Count; i++)
    {
        TextBox test = new TextBox();
        test.Text = row.Cells[i].Text.ToString();
        row.Cells[i].Controls.Add(test);
    }
}

尝试提取新值,并在此处列出newValues

foreach(GridViewRow row in GridView1.Rows) {
    if (row.RowType == DataControlRowType.DataRow) {
        bool isChecked = row.Cells[0].Controls.OfType < CheckBox > ().FirstOrDefault().Checked;
        if (isChecked) {
            string table = DropDownList1.Text.ToString();
            List < string > selectedValues = CheckBoxList1.Items.Cast < ListItem > ()
                .Where(li = > li.Selected)
                .Select(li = > li.Value)
                .ToList();

            List < string > newValues = new List < string > ();

            int userid = Convert.ToInt32(row.Cells[1].Text.ToString());
            //GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
            Label lblID = (Label) row.FindControl("WDB_Id");
            //TextBox txtname=(TextBox)gr.cell[].control[];
            for (int i = 4; i < selectedValues.Count + 4; i++) {
                newValues.Add(row.Cells[i].Text.ToString());

            }
        }
    }
}

由于

0 个答案:

没有答案
相关问题