Home Ask Login Register

Developers Planet

Your answer is one click away!

A. F. M. Golam Kibria February 2016

why does gridview create two colums when gridview columns are bound in aspx page

I have declared a gridview in aspx page as follows:

<td class="columnData"colspan="2"> 
<asp:GridView ID="grdDataView" runat="server">
<asp:boundfield datafield="divisionname" headertext="Division Name"/> 
<asp:boundfield datafield="designation" headertext="Designation"/> 
<asp:boundfield datafield="noofemployee" headertext="No of Employee"/>           

I bound gridview in a button click as follows:

grdDataView.DataSource = dt;

where dt contains column name divisionname,designation and noofemployee. It shows me the following output enter image description here

I need to avoid second group of column in black rectangular box. How this can be done?


Barry Franklin February 2016

You need to set the property "AutoGenerateColumns" to "false".

<asp:GridView ID="grdDataView" runat="server" AutoGenerateColumns="false">

or else it will generate the columns automatically along with the columns that you specify specifically in your code.

Post Status

Asked in February 2016
Viewed 3,159 times
Voted 8
Answered 1 times


Leave an answer

Quote of the day: live life