ASP.NET data grid

J

J. Babe

I'm building an ASP.NET application that stores/retrieves data using
MS-Access. I have a datagrid that I want to populate with a datatable.
However, I only want to display certain columns. I'm wondering how I
can manually assign specific columns from the datatable, to specific
columns in the data grid.
Thanks.
 
N

niceguy

You can do this by adding a DataGridTableStyle item to the datagrid. See
online help for DataGridTableStyle and DataGridColumnStyle.

Hope it helps...
 
J

J. Babe

I was wondering if you have to add a reference to System.Windows.Forms
to use the DataGridStyle class in a web application?
 
W

William F. Robertson, Jr.

No, System.Windows.Forms is only for desktop applications.

Only System.Web.UI.WebControls are valid controls for web apps.

bill
 
D

David Wier

Your best bet is to limit your query - -
Select Fname, Lname, Email from tablename

instead of Select * from TableName

However, no matter what your query - - you can use the AutoGeneratecolumns
property of the DataGrid:
AutoGeneratecolumns =False

Then, for each Field you need to use, use a boundcolumn tag (inside Column
tags) -- something like:
........AutoGenerateColumns="False"> '<--inside your DataGrid Tag

<columns>

<asp:BoundColumn DataField="product" HeaderText="Product"></asp:BoundColumn>

<asp:BoundColumn DataField="ProdID" HeaderText="ProductID"
ItemStyle-HorizontalAlign="Center"
HeaderStyle-HorizontalAlign="Center"></asp:BoundColumn>

<asp:BoundColumn DataField="Quantity" HeaderText="Quantity"
ItemStyle-HorizontalAlign="Center"
HeaderStyle-HorizontalAlign="Center"></asp:BoundColumn>

</columns>



David Wier
http://aspnet101.com
http://aspexpress.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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top