简体   繁体   English

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

[英]Update specific column in grid view from button click

How to update ASP.Net Gridview column with all rows acording to curent data... 如何根据当前数据更新所有行的ASP.Net Gridview列...

somethings like , column name is Issue Mode with 2 rows like N and F .. when i need to change data as, 诸如此类,列名是具有2行(如N and F ..)的发布模式,当我需要更改数据时,

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

if value is "N" set the value to CN

Visual example: 视觉示例:

在此处输入图片说明

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";
   }
}

On button Click Try this.. 在按钮上单击尝试此。

foreach ( DataRow dr in GridView1.Rows)    
{
    dr["columnname"].Value = "abcd";    
}
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";
}
}

Use RowDataBound event like following: 使用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";
        }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM