How do I only bind certain columns with a DataGrid?

G

Grant

I have the following code that binds a datatable to my datasource. Problem
is, the table has about 25 columns and I only really want to see 5 of those
columns. I know I can do it by changing my initial SQL query but that means
if I want to use other data later on I have to make another connection to
SQL and get the additional data.

Is there a way to only bind to certain columns in my table? It is a
webcontrol datagrid.

AllResultsDataGrid.DataSource = mySqlConnection.datasetHardware;
AllResultsDataGrid.DataMember = mySqlConnection.hardwareTableName;
AllResultsDataGrid.DataBind();

Thanks,

Grant
 
R

rbutch

yes, i would set the auto gen to false.
then go into the code behind and right before the end tag of the datagrid,bind the columns you want.


<Columns>
<asp:BoundColumn DataField="Actual_Column_Name" HeaderText="whatever"></asp:BoundColumn>
<asp:BoundColumn DataField="Actual_Column_Name" HeaderText="whatever"></asp:BoundColumn>

</Columns>

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 

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