Home All Groups Group Topic Archive Search About

How do I only bind certain columns with a DataGrid?

Author
11 Dec 2004 4:28 PM
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

Author
11 Dec 2004 5:46 PM
W.G. Ryan eMVP
Set the AutoGenerateColumns to false.  This should help
http://www.dotnet247.com/247reference/msgs/3/16848.aspx

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
Show quote
"Grant" <gpsn***@hotmail.com> wrote in message
news:eXDvs553EHA.2592@TK2MSFTNGP09.phx.gbl...
> 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
>
>
Author
13 Dec 2004 7:28 PM
rbutch@coair.com
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...
Author
14 Dec 2004 7:36 PM
Grant
thanks - works a bomb

Show quote
"W.G. Ryan eMVP" <WilliamRyan@NoSpam.gmail.com> wrote in message
news:OFId9j63EHA.1452@TK2MSFTNGP11.phx.gbl...
> Set the AutoGenerateColumns to false.  This should help
> http://www.dotnet247.com/247reference/msgs/3/16848.aspx
>
> --
> W.G. Ryan MVP (Windows Embedded)
>
> TiBA Solutions
> www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
> "Grant" <gpsn***@hotmail.com> wrote in message
> news:eXDvs553EHA.2592@TK2MSFTNGP09.phx.gbl...
>> 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
>>
>>
>
>

AddThis Social Bookmark Button