Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7540089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:33:12+00:00 2026-05-30T07:33:12+00:00

how would i change the value IBM to something arbitrary like Cisco in one

  • 0

how would i change the value IBM to something arbitrary like Cisco in one of the gridview events listed?

there can be varying columns in the dynamic gridview so would be nice to address the column by name.

namespace WebApplication1
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DataTable dt = new DataTable("TestTable");
            dt.Columns.AddRange(new DataColumn[] { new DataColumn("id"), new DataColumn("customername") });
            DataRow dr = dt.NewRow();
            dr[0] = "1";
            dr[1] = "Microsoft";
            dt.Rows.Add(dr);

            DataRow dr2 = dt.NewRow();
            dr2[0] = "2";
            dr2[1] = "IBM";
            dt.Rows.Add(dr2);

            GridView1.DataSource = dt;
            GridView1.DataBind();

        }

        protected void GridView1_DataBinding(object sender, EventArgs e)
        {

        }

        protected void GridView1_DataBound(object sender, EventArgs e)
        {

        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {

        }

        protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
        {

        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T07:33:13+00:00Added an answer on May 30, 2026 at 7:33 am

    This won’t work when AutogenerateColumns is set to true(default). You need to add the columns programmatically or declaratively(in aspx markup). Then you can use a TemplateField with a Control like Label that you can reference in codebehind:

    For example:

    <asp:GridView ID="GridView1" AutoGenerateColumns="false" OnRowDataBound="GridView1_RowDataBound" runat="server">
        <Columns>
            <asp:TemplateField HeaderText="Customer">
                <ItemTemplate>
                    <asp:Label ID="LblCustomer" runat="server"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    

    RowDataBound is perfect(for almost everything):

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if(e.Row.RowType == DataControlRowType.DataRow) {
            var row = ((DataRowView)e.Row.DataItem).Row;
            var lblCustomer = (Label)e.Row.FindControl("LblCustomer");
            var customerName = row.Field<String>( "customername" );
            if(customerName == "Microsoft") {
                customerName = "Cisco";
            }
            lblCustomer.Text = customerName;
        }
    }
    

    Edit: Ok, never needed to do such. But actually you can change the Microsoft values to Cisco even with AutoGenerateColumns set to true.

    DataBinding event is triggered before the GridView is databound. If you change the datasource before it’s bound to grid, you’ll be able to modify it:

    protected void GridView1_DataBinding(object sender, EventArgs e)
    {
        var tbl = (DataTable)((GridView)sender).DataSource;
        var msRows = tbl.AsEnumerable()
            .Where(r => r.Field<String>("customername") == "Microsoft")
            .Select(r => r);
        foreach(DataRow msRow in msRows) {
            msRow[ "customername" ] = "Cisco";
        }
    }
    

    Note: of course you can also use a simple loop instead of LINQ

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following problem: I would like to change value of ExpandableListView's cell
I would like to change the value of a property if it is a
I would like to change the value of RequestQueue elemt under @sorregion name[.='default'] to
I would like to change the self value of a float instance. I have
I would like to change the value in minChars depending on a select value
I would like to change the value of a ArrayList once a application is
I would like to change the value of an input field when the form
I would like to change the Row Source values in an Access table through
How would one change the view on the screen programmatically in an iPhone app?
Using Javascript, I would like change the background color of the numbers in an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.