I have a DataObject class who have method GetCategory
publicList<Category>
GetCategory()
Im using this method with GridView and ListView its working fine, even Edit and Delete are also working fine
To add AutoSorting functionality i added new method to class like below
public DataTable GetTable()
When i configure ObjectDataSource method for select operations GetTable(), GridView was unable to get fields information,
Is there any method to add Category Object to DataTable as DataFields?? or how can i solve this problem. Please note that if i configure field information manually it still works fine.
if retirm type of a method is Table or DataSet GridView could not get column information automatically. i want it to get column info at design time.
Hello:)
If you are using the Common DataTable, I'm afraid that's almost impossible because VS cannot execute dynamically your codes of creating a DataTable and map all the columns to the GridView.
However, I think You can use Strongly-Typed DataTable (TableAdapter) instead.
Hi there, did you use a table adapter as suggested after all? I find that columns are not in the Selected Fields list for editing when the return type for my select method is a DataTable.
Hi thank you for your reply. The link doesnt point to anything related to the subject?
I am using a gridview bound to an objectdatasource. The select method returns a datatable of objects of type "Record". If I use a datatable, the grid view will not list the columns for editing, so I had to create/add each bound field. (This doesnt sound
right)
Firstly should I use a List for the select method instead of a datatable?
I had my next problem when Updating. The updatemethod expects a parameter of "Record", however when executing, it does not have values in it. My SelectMethod is a stored procedure that returns multiple fields. I expected that I could just add updateparameters
manually in rowupdating allowing me to convert from string to datetime, string to decimal etc. If I dont do this the string values from the grid will cause type errors.
looks like you are mixing two different approaches,
1) if you want to bind gridview with datatable, i would recomend to use sqlDataSource object, where u will have to add sql statements for select, delete and update, after setting query statements configure gridview, in presence of update, delete queries,
gridview will itself understand to add editing fields,(editing templates) this method will allow you auto sort and much flexible but less secure
2) if you are using strongly typed objects, like u define model class for products, DAL and BLL layers to access products table, then its recomended to use objectdatasource, here i would strongly recomend to add component model signature to all methods,
for example
[DataObjectMethod(DataObjectMethodType.Select,true)]
public static IList<Product> GetAllProducts()
{
// your code here
}
above code is for select method, you need to add update and delete method in same way, this will help gridview to add editing controls, and delete functionality,
about your second question, to update automatically in database, please ensure you have configured well datasource object as discussed above, ensure that controls are two way binded, Bind("ProductID") is two way. in binding options you can also select format
for number and date time types
Irfan Ullah
Member
51 Points
42 Posts
Data Object select method with retun type DataTable, Fields info is not picking automatically
Jul 12, 2011 10:44 AM|LINK
Hi,
I have a DataObject class who have method GetCategory
public List<Category> GetCategory()
Im using this method with GridView and ListView its working fine, even Edit and Delete are also working fine
To add AutoSorting functionality i added new method to class like below
public DataTable GetTable()
When i configure ObjectDataSource method for select operations GetTable(), GridView was unable to get fields information,
Is there any method to add Category Object to DataTable as DataFields?? or how can i solve this problem. Please note that if i configure field information manually it still works fine.
Thanks.
tompy_nation
Contributor
5054 Points
1268 Posts
Re: Data Object select method with retun type DataTable, Fields info is not picking automatically
Jul 12, 2011 11:27 AM|LINK
Irfan Ullah
Member
51 Points
42 Posts
Re: Data Object select method with retun type DataTable, Fields info is not picking automatically
Jul 13, 2011 09:49 AM|LINK
Thanks for reply,
but what i exactly want is, on smart tag on GridView, when i choose datasource, GridView should refresh table schema,
if retirm type of a method is Table or DataSet GridView could not get column information automatically. i want it to get column info at design time.
thanks.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Data Object select method with retun type DataTable, Fields info is not picking automatically
Jul 14, 2011 02:35 AM|LINK
Hello:)
If you are using the Common DataTable, I'm afraid that's almost impossible because VS cannot execute dynamically your codes of creating a DataTable and map all the columns to the GridView.
However, I think You can use Strongly-Typed DataTable (TableAdapter) instead.
Thx
severn
Member
4 Points
5 Posts
Re: Data Object select method with retun type DataTable, Fields info is not picking automatically
Mar 17, 2012 03:25 PM|LINK
Hi there, did you use a table adapter as suggested after all? I find that columns are not in the Selected Fields list for editing when the return type for my select method is a DataTable.
Irfan Ullah
Member
51 Points
42 Posts
Re: Data Object select method with retun type DataTable, Fields info is not picking automatically
Mar 19, 2012 05:43 AM|LINK
please try tompy_nation's code it works fine, if you have any problem let me know in clear words what you want to do
severn
Member
4 Points
5 Posts
Re: Data Object select method with retun type DataTable, Fields info is not picking automatically
Mar 19, 2012 01:17 PM|LINK
Hi thank you for your reply. The link doesnt point to anything related to the subject?
I am using a gridview bound to an objectdatasource. The select method returns a datatable of objects of type "Record". If I use a datatable, the grid view will not list the columns for editing, so I had to create/add each bound field. (This doesnt sound right)
Firstly should I use a List for the select method instead of a datatable?
I had my next problem when Updating. The updatemethod expects a parameter of "Record", however when executing, it does not have values in it. My SelectMethod is a stored procedure that returns multiple fields. I expected that I could just add updateparameters manually in rowupdating allowing me to convert from string to datetime, string to decimal etc. If I dont do this the string values from the grid will cause type errors.
Is my approach incorrect?
Irfan Ullah
Member
51 Points
42 Posts
Re: Data Object select method with retun type DataTable, Fields info is not picking automatically
Mar 20, 2012 05:42 AM|LINK
looks like you are mixing two different approaches,
1) if you want to bind gridview with datatable, i would recomend to use sqlDataSource object, where u will have to add sql statements for select, delete and update, after setting query statements configure gridview, in presence of update, delete queries, gridview will itself understand to add editing fields,(editing templates) this method will allow you auto sort and much flexible but less secure
2) if you are using strongly typed objects, like u define model class for products, DAL and BLL layers to access products table, then its recomended to use objectdatasource, here i would strongly recomend to add component model signature to all methods, for example
[DataObjectMethod(DataObjectMethodType.Select,true)] public static IList<Product> GetAllProducts() { // your code here }above code is for select method, you need to add update and delete method in same way, this will help gridview to add editing controls, and delete functionality,
about your second question, to update automatically in database, please ensure you have configured well datasource object as discussed above, ensure that controls are two way binded, Bind("ProductID") is two way. in binding options you can also select format for number and date time types
hope this will help.