moving columns in an autogenerated gridview

Discussion in 'ASP .Net' started by JJ297, Apr 4, 2008.

  1. JJ297

    JJ297 Guest

    How do I move the select button to the last column in a gridview. I
    read to use the Gridview1_PreRender control and do this but I can't
    get it to work:

    Protected Sub GridView1_PreRender(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles GridView1.PreRender


    datacontrolfield temp = gridview1.Columns[0]
    If (temp Is CommandField) Then
    GridView1.Columns.RemoveAt(0)
    GridView1.Columns.Insert(2, temp)
    End If
    End Sub

    Here's my gridview:

    <asp:GridView ID="GridView1" runat="server" Width="812px"
    PageSize="100" DataKeyNames="TitleID"
    BorderColor="#CFB37D" BorderStyle="Solid" Font-Bold="False"
    Font-Names="Times New Roman"
    ForeColor="Red" HorizontalAlign="Center" AllowPaging="True">

    <Columns>
    <asp:CommandField ShowSelectButton="True">
    <ControlStyle ForeColor="Blue" />
    <ItemStyle VerticalAlign="Top" />
    </asp:CommandField>
    </Columns>
    </asp:GridView>

    Any suggestions?
    JJ297, Apr 4, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. MS
    Replies:
    1
    Views:
    414
  2. MS
    Replies:
    1
    Views:
    354
  3. Binny

    Autogenerated Columns

    Binny, Dec 15, 2003, in forum: ASP .Net
    Replies:
    8
    Views:
    582
    Munsifali Rashid
    Dec 15, 2003
  4. Luis Esteban Valencia
    Replies:
    0
    Views:
    674
    Luis Esteban Valencia
    Jan 11, 2005
  5. MikeG

    Sorting a datagrid with autogenerated columns

    MikeG, Jun 23, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    128
    MikeG
    Jun 23, 2004
Loading...

Share This Page