Select columns from dataset

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?
 
S

Scott Mitchell [MVP]

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!
 
C

Curt_C [MVP]

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
 
J

Jeffrey Palermo [MCP]

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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top