Solved

Datagrid Datasource

Posted on 2006-07-18
6
418 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 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Where can I ask about my ASP.NET MVC project? 6 36
Video Player 11 23
Hey!! 5 33
Following an example - Why do I need to click Save button twice? 3 25
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

776 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