for gridview with dynamic column you need to set some property to your grid like this...
AutoGenerateColumns="true"
so it will genrate the number of column as per your data, means if your datatable contains 4 column data then the grid will show 4 column, or if it will contains 2 column data then it will display 2 columns....
like if your data table like this...
Table1
STUDENTNAME,ROLNO,CITY,DEPARTMENT
then the grid will contains this column..
or if the data will be like this..
STUDENTNAME,ROLNO
then it will show only 2 column in grid...
so for this you need to fire the select query like this. or provide datasource to grid with this criteria....
Grid Design like this...
<asp:gridview id="GridView1" runat="server" autogeneratecolumns="true" xmlns:asp="#unknown">
</asp:gridview>