How do I only bind certain columns with a DataGrid?

  • Thread starter Thread starter Grant
  • Start date Start date
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
 
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...
 
Back
Top