You must Sign In to post a response.
  • Category: ASP.NET

    Change Grid view Header Text

    Hello,

    I am using Grid View in my Project.. and i have Some name changes for Grid view Header name.

    I want that name to be change using one shared method ? Can i Write Code in Gridview- Header Text ?

    I dont want to use GridView Row DataBound method. that i know.

    Any Suggestions ?
  • #761438
    Hi

    You can go through Below code


    DataTable dt1 = new DataTable();
    DataRow dr;
    dt1.Columns.Add("lblsectn");
    dt1.Columns.Add("lblproductname");
    dt1.Columns.Add("lbllotno");
    dt1.Columns.Add("lblmrp");
    dt1.Columns.Add("lblsupliername");
    dt1.Columns.Add("lblsizee");
    dr = dt1.NewRow();
    dr[0] = 1;
    dr[1] = "Mouse";
    dr[2] = 180;
    dr[3] = 123;
    dr[4] = "HCL";
    dr[5] = 196;
    dt1.Rows.Add(dr);

    dr = dt1.NewRow();
    dr[0] = 2;
    dr[1] = "Keyboard";
    dr[2] = 280;
    dr[3] = 323;
    dr[4] = "HCL";
    dr[5] = 496;
    dt1.Rows.Add(dr);


    dr = dt1.NewRow();
    dr[0] = 3;
    dr[1] = "PenDrive";
    dr[2] = 380;
    dr[3] = 423;
    dr[4] = "HCL";
    dr[5] = 696;
    dt1.Rows.Add(dr);

    ddsales.DataSource = dt1;
    ddsales.DataBind();


    ddsales.HeaderRow.Cells[0].Text = "Name";
    ddsales.HeaderRow.Cells[1].Text = "EmpNo";
    ddsales.HeaderRow.Cells[2].Text = "Amount";


    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #761442
    Hello Chirag,

    You can change the header text by using below code :

    GridView1.HeaderRow.Cells[0].Text = "Header Name Of Column1";
    GridView1.HeaderRow.Cells[1].Text = "Header Name Of Column2";
    GridView1.HeaderRow.Cells[2].Text = "Header Name Of Column3";

    Hope this will help you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #761464
    Hi,

    If you want to change the GridView Header dynamically, then use below lines of code whenever you want to change.


    gv.HeaderRow.Cells[0].Text = "Change Header";


    Hope this will helpful to you...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


Sign In to post your comments