从按钮单击更新网格视图中的特定列

时间:2013-12-27 05:48:00

标签: c# asp.net gridview

如何根据curent数据更新所有行的ASP.Net Gridview列...

某些事情,例如,列名是问题模式,有2行,如N and F ..当我需要更改数据时,

if value is "F" set the value to "CF" or

if value is "N" set the value to CN

视觉示例:

enter image description here

4 个答案:

答案 0 :(得分:2)

foreach ( GridViewRow row in GridView1.Rows)
{
   if(row.Cells[0].Text=="F")
   {
       row.Cells[0].Text ="CF";
   }
   else if(row.Cells[0].Text=="N")
   {
       row.Cells[0].Text ="CN";
   }
}

答案 1 :(得分:1)

开启按钮点击试试..

foreach ( DataRow dr in GridView1.Rows)    
{
    dr["columnname"].Value = "abcd";    
}

答案 2 :(得分:1)

foreach ( GridViewRow rw in GridView1.Rows)
{
if (rw.Cell[0].Text =="F")
{
        rw.Cells[0].Text ="CF";
}
else if (rw.Cells[1].Text =="N")
{
       rw.Cells[1].Text ="CN";
}
}

答案 3 :(得分:1)

使用 RowDataBound 事件,如下所示:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
        if(e.Row.Cells[0].Text =="F")
        {
            e.Row.Cells[0].Text = "CF";
        }
        else if (e.Row.Cells[0].Text == "N")
        {
            e.Row.Cells[0].Text = "CN";
        }
}