Results 1 to 5 of 5

Thread: Change Column order in Datagrid

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Location
    Three Rivers, MI
    Posts
    354

    Change Column order in Datagrid

    I am trying to move the show band button to the last column instead of the first. Can some one help me get it done. Here is the page Band Page.

    The asp code looks like this:
    VB Code:
    1. <asp:datagrid
    2.     id="dgBands"
    3.     runat="server"
    4.     BorderColor="#CC9966"
    5.     BorderStyle="None"
    6.     BorderWidth="1px"
    7.     BackColor="White"
    8.     CellPadding="4">
    9.     <FooterStyle
    10.         ForeColor="#330099"
    11.         BackColor="#FFFFCC">
    12.     </FooterStyle>
    13.     <SelectedItemStyle
    14.         Font-Bold="True"
    15.         ForeColor="#663399"
    16.         BackColor="#FFCC66">
    17.     </SelectedItemStyle>
    18.     <ItemStyle
    19.         ForeColor="#330099"
    20.         BackColor="White">
    21.     </ItemStyle>
    22.     <HeaderStyle
    23.         Font-Bold="True"
    24.         ForeColor="#FFFFCC"
    25.         BackColor="#990000">
    26.     </HeaderStyle>
    27.     <PagerStyle
    28.         HorizontalAlign="Center"
    29.         ForeColor="#330099"
    30.         BackColor="#FFFFCC">
    31.     </PagerStyle>
    32.     <Columns>
    33.         <asp:ButtonColumn
    34.             Text="Show Band"
    35.             CommandName="Select"
    36.             ButtonType="LinkButton">
    37.             </asp:ButtonColumn>
    38.         </Columns>
    39. </asp:datagrid>
    Last edited by BukHix; Aug 22nd, 2005 at 09:57 PM.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Change Column order in Datagrid

    Where are the rest of your columns? You should place all of them in your <Columns> section, in the order you want them to appear in.

  3. #3
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Change Column order in Datagrid

    The other columns are generated automatically...so any preset bound columns always appear 1st.
    Turn off the property to auto generate columns based on the datasource.
    Then add the columns manually to the datagrid, like you have with the one above, and arrange them how you want.

    Woka

  4. #4
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Change Column order in Datagrid

    So you would have something like:
    Code:
    <Columns>
    	'Main columns
    	<asp:BoundColumn DataField="UserID" HeaderText="ID"></asp:BoundColumn>
    	<asp:BoundColumn DataField="Username" HeaderText="Username"></asp:BoundColumn>
    	<asp:BoundColumn DataField="Password" HeaderText="Password"></asp:BoundColumn>
    	'Your button column
    	<asp:ButtonColumn Text="Show Band" CommandName="Select" ButtonType="LinkButton"></asp:ButtonColumn>
    </Columns>
    Woka

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Location
    Three Rivers, MI
    Posts
    354

    Re: Change Column order in Datagrid

    Thanks, turning off the auto generting columns did the trick.

    I didn't end up with exactly what I had in mind but this exercise was just a self challenge to move my ASP.net skills beyond the novice level to something a little more advanced.

    By the way does anybody know the answer to 24, 45, 46, 47 or 73?

    The project can be found here now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width