Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Datagrid Datasource

Posted on 2006-07-18
6
Medium Priority
?
423 Views
Last Modified: 2008-02-07
Hi Guys,

Could anyone pls tell me if its possible while binding the data to datasource you only get certain columns from the datatable like 1 - 5 and ignore the last column...


DataGrid1.DataSource = ds.Tables[0];
DataGrid1.DataBind();

Cheers
--Nitin
0
Comment
Question by:radhakrishan
  • 2
  • 2
  • 2
6 Comments
 
LVL 23

Expert Comment

by:apresto
ID: 17128929
Hi radhakrishan,

Is the datatable being populated from a database - if so could you not just change your sql?

Apresto
0
 
LVL 23

Accepted Solution

by:
apresto earned 1000 total points
ID: 17128934
Otherwise have a look here, shows you how to hide datagrid columns:

http://www.c-sharpcorner.com/Code/2003/June/HideDataGridColDyna.asp
0
 

Expert Comment

by:annihil8
ID: 17129002
I would use a tablestyle

DataGridColumnStyle colstyle;
_dg.TableStyles.Clear();

DataGridTableStyle tablestyle = new DataGridTableStyle();
tablestyle .MappingName = "xxxNAME OF TABLE";

//
colstyle = new DataGridTextBoxColumn();
colstyle.MappingName = "xxxNAME OF COLUMNxxx";
colstyle.HeaderText = "Free to choose";
colstyle.Width = 100;
tablestyle .GridColumnStyles.Add(colstyle);
                  
//Do this for every col you want to show
                  
_dg.TableStyles.Add(tablestyle );

Grtz,
Annihil8
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:radhakrishan
ID: 17129099
Hi Annihil8,

DataGrid1.TableStyles.Clear();
                        DataGridTableStyle tablestyle = new DataGridTableStyle();
                        tablestyle.MappingName = "tbCategories";
                        colstyle = new DataGridTextBoxColumn();
                        colstyle.MappingName = "Start Date";
                        colstyle.HeaderText = "Free to choose";
                        colstyle.Width = 100;
                        tablestyle .GridColumnStyles.Add(colstyle);
                        DataGrid1.TableStyles.Add(tablestyle);

Doing this gives me loads of errors:

--System.Web.UI.WebControls.DataGrid' does not contain a definition for 'TableStyles'
--The name 'colstyle' does not exist in the class or namespace 'CCalendar.Daydescription'

And how do I tell it to take the data from dataset
do I still need to say:
datagrid1.datasource = ds.tables[o]

0
 

Author Comment

by:radhakrishan
ID: 17129179
Hi apresto ,
The link you provided gave me exactly wat i was lookin for.
Cheers.
0
 

Expert Comment

by:annihil8
ID: 17129195
Allright :D

My code is for winforms and even on CF. I'm not familiar at all with webdevelopment so I can't say where the error is.

-Colstyle need to be declared as :
DataGridColumnStyle colstyle; // but you will get the error that DataGridColumnStyle is unknown
-you still have to do datagrid1.datasource = ds.tables[o] after the
DataGrid1.TableStyles.Add(tablestyle);

Following msdn it should work, but I got the same errors like you when testing it on webform :D Probably a reference or something, but I can't tell it exactly.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question