Take the 2-minute tour ×

I have a asp:GridView wich in code behind is asigned to a List with Objects.

gwMyGridview.DataSource = test; // test is a list with some objects (two fields)

I can add buttons and stuff to the columns, but my data (two columns) are always the last two columns. I know BoundField can be used, but I still get two columns in the end. How can i do this: column1 = data1, column2 = button, column3 = data. Now it looks like this: button, data, data

Thanks in advance!

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Don't let the GridView to auto generate the columns. To do this, follow these steps:

1- Click on the GridView's Tasks (little arrow on top of the GridView when you click on it) and click on Edit Columns, and uncheck the "Auto-Generate fields" field, or from the Markup set the AutoGenerateColumns property to false

2 - Add your columns manually to the GridView, by either adding them in the previous dialog (Fields) or in the markup, in the exact order you want them to a appear in your GridView:

        <asp:BoundField DataField="data1" HeaderText="Data1" />
        <asp:TemplateField HeaderText="CustomColumn"></asp:TemplateField>
        <asp:BoundField DataField="data2" HeaderText="Data2" />

After that you can bind normally.

share|improve this answer
Nice! Hold on I will try this! –  Half_Baked Apr 19 '13 at 15:29
YES! Thank you, it worked perfectly. AutoGenerateColums="False" did it! –  Half_Baked Apr 19 '13 at 15:34
Nice, glad it worked :) –  Hanlet Escaño Apr 19 '13 at 15:34
It really helped! :) Now I just need to find out how to read if a radio button inside the GridView is selected... :) –  Half_Baked Apr 19 '13 at 15:43
Post another question with this, share the link and specify if you want to know the value within asp.net or javascript ;), but of course, make sure there is not asked previously first :p –  Hanlet Escaño Apr 19 '13 at 15:44
show 2 more comments

Your Answer


