473,396 Members | 2,070 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Binding Struct to DataGrid

Hi I am returning an array of struct from my webservice. Is there a way to bind that array of struct to DataGrid. I am using C#. Following is my struct.

Expand|Select|Wrap|Line Numbers
  1. //Struct to be sent
  2. public struct UserDataSent
  3. {
  4. public string userID , fName , lName , IMO , status, businessAddress, city, state, zip, telephoneNumber, mail;
  5. }
Jul 12 '07 #1
5 5038
nateraaaa
663 Expert 512MB
Hi I am returning an array of struct from my webservice. Is there a way to bind that array of struct to DataGrid. I am using C#. Following is my struct.

Expand|Select|Wrap|Line Numbers
  1. //Struct to be sent
  2. public struct UserDataSent
  3. {
  4. public string userID , fName , lName , IMO , status, businessAddress, city, state, zip, telephoneNumber, mail;
  5. }
I know that you can use an array or arraylist as the datasource of a datagrid. Could you add the items of the struct into an array and then use the array as the datasource of your datagrid?

Nathan
Jul 12 '07 #2
I know that you can use an array or arraylist as the datasource of a datagrid. Could you add the items of the struct into an array and then use the array as the datasource of your datagrid?

Nathan
Nathan,
it still doesnt work. If I turn Auto Generate Column to false and try to bind every field that it says "A field or property with the name 'LName' was not found on the selected datasource.

And if I turn Auto Generate columns to true and dont bind any column manually then it says

System.Web.HttpException: DataGrid with id 'dgCheck' could not automatically generate any columns from the selected data

What I am doing wrong?
Jul 12 '07 #3
Plater
7,872 Expert 4TB
Are you using a DataGrid or a DataGrid view?

The datagridview's datasource objects seem to auto-create columns based on public methods and not public variables

Such as:
Expand|Select|Wrap|Line Numbers
  1. public string MyString
  2. {
  3.    get
  4.    {
  5.       return "hi there";
  6.    }
  7. }
  8.  
Would create a column called "MyString"
Jul 12 '07 #4
Are you using a DataGrid or a DataGrid view?

The datagridview's datasource objects seem to auto-create columns based on public methods and not public variables

Such as:
Expand|Select|Wrap|Line Numbers
  1. public string MyString
  2. {
  3.    get
  4.    {
  5.       return "hi there";
  6.    }
  7. }
  8.  
Would create a column called "MyString"
I am using datagrid. And also I have struct defined as public with public variables in it.
Jul 12 '07 #5
As Plater said,

You need to put properties inside your struct. The gridview binds to public properties, not fields.

Expand|Select|Wrap|Line Numbers
  1. //Struct to be sent
  2. public struct UserDataSent
  3. {
  4. public string userID , fName , lName , IMO , status, businessAddress, city, state, zip, telephoneNumber, mail;
  5.  
  6. public string UserID {[indent]get { return userID; }
  7. }
  8.  
  9. ...
  10.  
  11. }
  12.  
It maybe possible to bind to fields using code attributes, but if it is I don't what the attribute is.

Cheers,
Graham
Jul 19 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Ann Morris | last post by:
INTRODUCTION One of the most powerful aspects of .NET and Windows Forms is data binding. Data binding is the process of associating user interface (UI) elements with a data source to generate a...
1
by: Nony Buz | last post by:
I have an Array of a struct that contains int's and a string. I would like to display that in a DataGrid, how do I do it? There will be an extra field that will get updated which is not in the...
8
by: Richard L Rosenheim | last post by:
I have a dataset containing a parent table related to a child table. The child table contains an ID field (which is configured as autonumber in the datatable), the ID of the parent, plus some...
5
by: Brad Shook | last post by:
I am trying to bind one column of a datagrid to a seperate textbox and the rest of the fields to a datagrid. the comments are too large to fit in a datagrid so I created a textbox below the...
6
by: p.mc | last post by:
Hi all, I'm having major problems with a userControl which contains a datagrid. My problem concerns data binding. The Page_Load() procedure calls the DataBind procedure to bind the datagrid...
3
by: no | last post by:
Hi all, I have a dataset that contain 2 tables and a relationship between them (master detail). I bind this dataset to a form that include some textboxes that bind to the parent record, and a...
1
by: Stephen Barrett | last post by:
I have an application that was originally built with ASP.Net 1.1. We finally got permission to migrate to 2.0. Due to time constraints we migrated the web projects to 2.0 web application...
15
by: Tom Gur | last post by:
Hi, What is early/late binding ?
4
by: aarklon | last post by:
Hi all, recently a friend asked me is there any dynamic binding in C...?? to which i answered AFAIK it is in C++ only, but he says it is valid in C. if dynamic can be implemented via function...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.