.Net 2.0 C# GridView question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jason Huang

    .Net 2.0 C# GridView question

    Hi,

    Would someone tell me how to manipulate the Header of a GridView?
    My DataSet is like this:

    _id _name
    1 John
    2 Mary

    But I want the GridView in my webform to show up like this:

    ID Name
    1 John
    2 Mary

    Thanks for help.


    Jason


  • Prashanth Rao

    #2
    Re: .Net 2.0 C# GridView question

    Jason,

    You can change the header text of the GridView column by:

    GridView1.Colum ns[0].HeaderText = "ID";

    Regards,
    Prashanth.


    On May 16, 1:28 pm, "Jason Huang" <JasonHuang8... @hotmail.comwro te:
    Hi,
    >
    Would someone tell me how to manipulate the Header of a GridView?
    My DataSet is like this:
    >
    _id _name
    1 John
    2 Mary
    >
    But I want the GridView in my webform to show up like this:
    >
    ID Name
    1 John
    2 Mary
    >
    Thanks for help.
    >
    Jason

    Comment

    • =?Utf-8?B?YnVybG8=?=

      #3
      Re: .Net 2.0 C# GridView question

      Another way is to define the column your self that way you know for shaw the
      heading corresponds to the correct data see below:

      //disable auto column generation
      MyGridView.Auto GenerateColumns = false;

      //define id column
      BoundField field = new BoundField();
      field.DataField = "Id";
      field.HeaderTex t = "TestId";
      MyGridView.Colu mns.Add(field);

      //define Name column
      field.DataField = "Name";
      field.HeaderTex t = "TestName";
      MyGridView.Colu mns.Add(field);

      MyGridView.Data Source = _myDataSource;
      MyGridView.Data Bind();

      "Prashanth Rao" wrote:
      Jason,
      >
      You can change the header text of the GridView column by:
      >
      GridView1.Colum ns[0].HeaderText = "ID";
      >
      Regards,
      Prashanth.
      >
      >
      On May 16, 1:28 pm, "Jason Huang" <JasonHuang8... @hotmail.comwro te:
      Hi,

      Would someone tell me how to manipulate the Header of a GridView?
      My DataSet is like this:

      _id _name
      1 John
      2 Mary

      But I want the GridView in my webform to show up like this:

      ID Name
      1 John
      2 Mary

      Thanks for help.

      Jason
      >
      >
      >

      Comment

      • Prashanth Rao

        #4
        Re: .Net 2.0 C# GridView question


        One more way is to set it in the Design time like this:

        <asp:GridView ID="GridView1" runat="server" AllowPaging="Tr ue"
        AllowSorting="T rue" AutoGenerateCol umns="False">
        <Columns>
        <asp:TemplateFi eld HeaderText="Fir st Name"
        SortExpression= "FirstName" >
        <ItemTemplate >
        <asp:Label ID="Label1" runat="server" Text='<%#
        Bind("Id") %>' Width="108px"></asp:Label>
        </ItemTemplate>
        <ItemTemplate >
        <asp:Label ID="Label4" runat="server" Text='<%#
        Bind("Name") %>' Width="108px"></asp:Label>
        </ItemTemplate>
        </asp:TemplateFie ld>
        </gridview>


        Comment

        Working...