Click here to Skip to main content
11,483,586 members (67,260 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
How to solve this error...
help
cannot convert from 'System.Web.UI.WebControls.GridView to 'System.Windows.Forms.DataGridView
Posted 29-Nov-12 1:55am
sahmed4567
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The message is pretty clear: You are trying to assign a value to a variable that is not capable of holding it. In this case, you are trying to load a GridView into a DataGridView - they are very different classes and not related.

Without the relevant code fragment, there isn't a lot more I can do...
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You cannot convert webcontrol to windows form control. To resolve this refer webcontrol in web application and refer windows control in windows application. see the highligted difference of namespaces below.

'System.Web.UI.WebControls.GridView to 'System.Windows.Forms.DataGridView
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Answer is already in your error message...I think your going to assign webControls GridView to windows form DataGridView. Those are very different objects and this kind conversion is cannot be done...
Why don't you try assign Data Source...
If there is a way to load data to your Windows form DataGridView.You can assign it like below
 
Web.UI.WebControls.GridView gV = new Web.UI.WebControls.GridView();
 
gV.DataSource= dataTableObject; // data table object


you can assign your System.Windows.Forms.DataGridView data source to this data table object
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

gridview is a web control but DataGridView is a windows application control.so u can't convert web control into windows control.....
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 305
1 Frankie-C 195
2 Raje_ 155
3 OriginalGriff 142
4 Abhipal Singh 108
0 Sergey Alexandrovich Kryukov 8,444
1 OriginalGriff 7,903
2 Sascha Lefèvre 3,114
3 Maciej Los 2,521
4 Richard Deeming 2,370


Advertise | Privacy | Mobile
Web02 | 2.8.150520.1 | Last Updated 29 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100