Solved

Datagrid Datasource

Posted on 2006-07-18
6
419 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 250 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

691 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