Gridview Header positioning

Last post 04-07-2009 1:38 PM by Franco_1. 2 replies.

Sort Posts:

  • Gridview Header positioning

    04-06-2009, 3:24 PM
    • Member
      4 point Member
    • Franco_1
    • Member since 08-22-2008, 12:41 PM
    • Posts 41

    I have a gridview with one textbox that users will be entering data.

    I also have a field in the gridview that is populated from a database.

    I want the database field to be the first on in the grid view, but instead,

    the itemtemplate appears first in the gride view during runtime.

    How can I make the first column of the gridview to be ALWAYS the first column during runtime?

    Below is the code for the itemtemplate.

    <asp:GridView ID="gvClientView" runat="server" BorderStyle="Ridge" BorderWidth="4px"

    CellPadding="4" ForeColor="#333333" GridLines="None" Style="z-index: 102;

    left: 306px; position: absolute; top: 88px">

    <RowStyle BackColor="#EFF3FB" />

    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />

    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />

    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />

    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />

    <EditRowStyle BackColor="#2461BF" />

    <AlternatingRowStyle BackColor="White" />

    <Columns>

    <asp:TemplateField HeaderText="Revenue">

    <ItemTemplate>

    <asp:TextBox ID="txtRev" runat="server" Text="Hello" ></asp:TextBox>

    </ItemTemplate>

    </asp:TemplateField>

     

    </Columns>

     

    </asp:GridView>

  • Re: Gridview Header positioning

    04-06-2009, 5:09 PM
    Answer
    • Contributor
      2,153 point Contributor
    • kammie
    • Member since 12-16-2008, 5:52 PM
    • Washington, DC
    • Posts 352

    When you have AutoGenerateColumns property set to True, which in your case is True by default, all the explicitly declared columns will be rendered first. All the Auto generated columns are rendered after that. You cannot change this behavior.

    If you want your TemplateField to be displayed later, you need to manually create the column in the code-behind page once your data is binded.

    Refer this link to create Template Fields dynamically...

    http://www.codeproject.com/KB/aspnet/create_template_columns.aspx

    Hope it helps.

    KAMMIE
    Don't forget to Mark as Answer on the post that helped you. It encourages them to share their knowledge, and it helps others to easily identify the solution.
  • Re: Gridview Header positioning

    04-07-2009, 1:38 PM
    • Member
      4 point Member
    • Franco_1
    • Member since 08-22-2008, 12:41 PM
    • Posts 41

    Thanks for the info. The headers are now position the way that i want them.

    Is there a VB version of the link you sent? All help out there I came across

    are in C#.

Page 1 of 1 (3 items)