Select columns from dataset

  • Thread starter Thread starter DaveF
  • Start date Start date
D

DaveF

I have a dataset with about 30 columns, I want to select 3 specific columns
of data
from that dataset to populate a datagrid. How do I do this?
 
DaveF said:
I have a dataset with about 30 columns, I want to select 3 specific columns
of data
from that dataset to populate a datagrid. How do I do this?

Set AutoGenerateColumns to False and explicitly specify what columns to
diplay. I.e.,

<asp:DataGrid runat="server" ... AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="DataSetFieldName1" ... />
<asp:BoundColumn DataField="DataSetFieldName2" ... />
...
<asp:BoundColumn DataField="DataSetFieldNameN" ... />
</Columns>
</asp:DataGrid>

I also would implore you to read my An Extensive Examination of the
DataGrid article series, which starts at:
http://aspnet.4guysfromrolla.com/articles/040502-1.aspx

There's also my book that focuses specifically on the DataGrid,
DataList, and Repeater Web controls - ASP.NET Data Web Controls Kick
Start [http://www.4guysfromrolla.com/ASPScripts/Goto.asp?ID=148]

--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 
in the datagrid's <columns> section you can specify them. Use the property
builder from the designer to walk you through it. They will be BoundColumns
 
I would agree that this is the simplest way to do it. You already have the
DataSet, so just format your grid to display what you need.

--
Best regards,
Jeffrey Palermo
Blog: http://dotnetjunkies.com/weblog/jpalermo


Scott Mitchell said:
DaveF said:
I have a dataset with about 30 columns, I want to select 3 specific columns
of data
from that dataset to populate a datagrid. How do I do this?

Set AutoGenerateColumns to False and explicitly specify what columns to
diplay. I.e.,

<asp:DataGrid runat="server" ... AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="DataSetFieldName1" ... />
<asp:BoundColumn DataField="DataSetFieldName2" ... />
...
<asp:BoundColumn DataField="DataSetFieldNameN" ... />
</Columns>
</asp:DataGrid>

I also would implore you to read my An Extensive Examination of the
DataGrid article series, which starts at:
http://aspnet.4guysfromrolla.com/articles/040502-1.aspx

There's also my book that focuses specifically on the DataGrid,
DataList, and Repeater Web controls - ASP.NET Data Web Controls Kick
Start [http://www.4guysfromrolla.com/ASPScripts/Goto.asp?ID=148]

--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 
Back
Top