0

How to update ASP.Net Gridview column with all rows acording to curent data...

somethings like , column name is Issue Mode with 2 rows like N and F .. when i need to change data as,

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

if value is "N" set the value to CN

Visual example:

enter image description here

1
  • you need to loop over GirdView.Rows then each Row.Cells. Check the Cell.Header. Commented Dec 27, 2013 at 5:50

4 Answers 4

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";
   }
}
Sign up to request clarification or add additional context in comments.

1 Comment

in this case how to fined the specific column ... <asp:TemplateField HeaderText="Issue Mode"> <ItemTemplate> <asp:Label ID="IssueMode" runat="server" Text='<%# Bind("IssueMode") %>'></asp:Label> </ItemTemplate> </asp:TemplateField>
1

Use RowDataBound event like following:

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

Comments

1

On button Click Try this..

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

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.