Forms Data Controls :: What Kinds Of Objects Can Set For A GridView.DataSource
May 14, 2010MyGridView.DataSource = <<<what kind of objects here?>>>
DataTable works. What else?
MyGridView.DataSource = <<<what kind of objects here?>>>
DataTable works. What else?
have some Objects, lets say Employee and Role defined as below and I have defined relationships in my database that gives me a list of objects say employees and thanks to my framework each employee object also has a Role object linked via the RoleIDID, UserName, Password, Email, RoleIDRoleID, RoleNameSo in code I can do something like this
Employee emp = dataService_GetEmployeeByID(1);
string RoleName = emp.Role.RoleName;
Now here is my problemI can bind any object in a repeater and it works fine for the first level in my relationship
For instance <%# Eval("UserName") %>
But I need to be able to show the details for my child objects as well (Role) so something like this (which does not work)
<%# Eval("Role.RoleName") %>
I know how to bind a simple objects to a dropdown list. However I am having problems binding my objects which contains sub objects to the control.i.e. with simple object i just do ddl.DataValueField = "myproperty"
with my objects they contains sub objects which i want to bind. I have tried ddl.DataValueField = "sub-object.myproperty" which doesnt work.
I have a List of Customers. Now I want to display these customers in a gridview and that is easy. I just set the datasource and use the databind method of the gridview. (I use template fields). But now I want to display FirstName and LastName of the customer as one column.I am aware of how to use the rowdatabound event to manipulate the gridviewrow's controls, but I am not sure how to gain access to the customer object within this method.So here is some code which of course not works.
protected void grdVirtualCustomers_RowDataBound(object sender, GridViewRowEventArgs e)
{
System.Web.UI.WebControls.GridViewRow row = e.Row;
((Label) row.FindControl("lblName").).Text=Customer.FirstName + " " Customer.LastName;
}
I'm creating in my code a list of object which must be displayed later in a table.
In Winforms I'd simply bind the DataGridView to the list, and everything is fine.
However, when I try to set the GridView's data source to the list, nothing happens, and I can't find a way to do this with any of the procided data sources(Such as ObjectDataSource, etc.).
I have been reading alot about this and for some reason I am just not able to grasp the concept. Hopefully someone here can enlighten me.As an example situation I have a collection of strongly typed User objects that represent a database table, and some properties that represent its columns: UserID(PK), Username,FirstName,LastName, etc..Here are some of my requirements/goals:1. Users/Objects needs to be bound to the gridview programatically.2. I do not want to update the database right away, I only want the underlying collection to be updated. I would like to call the database update method myself when I am ready.
3. I do not want the primary key stored on the client side.Summary:So I bind a List<Users> to a gridview with the appropriate bound fields set up, I exlude bound fields such as primary key because I don't want it being changed/hacked by the client side. When I edit and update a row it is saved back to the collection of objects. I will iterate through the objects manually at a later time and commit them to database.
Questions:1. Can I cast a gridview row directly back to my object, in the RowUpdating or RowUpdated events? I am assuming I can't... So....2. How can I reference back my original collection if the gridview does not contain a primary key?3. Where do I store my collection, should it be in Session or should I recreate it on each postback?Sorry if any of this is confusing, let me know if you need clarification.
I created a class library: PRTreatmentReviews. I created a reference for the class library on the website. I checked the property pages and the reference to the class is there. I put objectdatasource on a page and tried to pick up the PRTreatmentReviews class but it's not there? The Class
[Code]....
I have 2 Linq to Entity queries, here they are:
[Code]....
In "query" there are several columns, 2 of them are NIIN and Qty. In "objViewDDRT" there are only 2 columns, they are NIIN and AvailBalance.
What I need to do is for each row in "query" check to see if the NIIN is in "objViewDDRT", and if it is get the AvailBalance for that NIIN from objViewDDRT.
I was put in charge of a database that has no source control, and all work was done in the database. I want to pull all the objects (stored procs, views, tables) from the database, and add to my new source control.
Is there a way to get all the objects into individual files out of a database?
Our database is SQL 2005. I have Visual Studio 2005/2008/2010 (beta 2) at my disposal.
Entity framework easily allows for this but how can I detach objects in linq to sql?
View 1 RepliesI have a gridview control that displays expenses claims received from clients. I have a template field that contains a checkbox - if this is ticked, a value from the gridview is added to a variable and this is outputted to a label control.
What I then want to do is to update the database according to which row has been ticked. I have so far the following code that adds each value to an array, which I was then hoping to access in the sql query i.e. Update table set value = value where id = (id's added to array)..
Code as follows - so far I'm just displaying the count of values in the array to make sure they are actually being added:
[Code]....
For some reason, some of the fields in our database use a different collation than the default. There doesn't seem to be a pattern as to which fields use the different collations, so I'd like to run a query to find which fields use this collation and change them to the default. Does anyone know how to do this?
View 2 RepliesI have two business objects mapped via LINQ to tables. One of the objects contains an instance of the other object and share a key as an identifier.I want to retrieve Class A and within class A all of Class B's values as well. What I am doing is this:
[Code]....
[Code]....
This seems a little clunky, as in slow. Is there a better way to get the Class B (User) information without making a query every time?
im developing a silverlight project using silverlight 3, vs2008 and linq2sql. when projects starts, im storing all the data from database into some static list variables. so when ever i need data, im reading it from those static list variables. all i want to know is, is it good to store data in static list variables and use it when ever necessary or is it good to get data directly from DataClassesDataContext object like db.mytable. which is the rite and fastest way or retrieving data. i mean which will use less connections to database?
View 2 RepliesI have a really weird problem. It actually made me restart the computer.
View 1 RepliesI'm working on a project in which we have a database, data layer (entity framework), business layer and web/UI layer.I want to use ASP.NET Dynamic Data for the web layer, but don't want it to access the data layer or database, as I want it to be purely running off business logic, and not directly accessing the data.However, it appears that Dynamic Data only allows Linq-to-SQL or entity framework data sources to be used.Has anyone used it with business-layer objects instead?
View 1 RepliesWhich is better from the performance point of view Wizard Bound Controls or Binding Controls by manual ADO.NET Coding?
View 2 RepliesI would like to write Set difference minus operation with Linq on list objects using Except method. [Code]....
Tha above code always returns lstrbb objects.
I recognized that based on a context in which I want to use some parameters, there are at least 4 kinds of encoding that are necessary to avoid corrupted code being executed :
Javascript encoding when constructing a javascript code, e.g.
var a = "what's up ?"
var b = "alert('" + a + "');"
eval(b); // or anything else that executes b as code
[Code]....
My DataTable is programatically generated, and contains objects of type JobInstance in the cells.
[Code]....
When I bind this DataTable to an ASP GridView, it only displays the first column. But if I remove the "typeof(Job)" when creating the column (the line with // !!!), the GridView displays all the columns by showing the result of JobInstance.ToString() in the cells. However, I have no access to the underlying JobInstance object, only the string values that are being displayed.
I need access to the JobInstance object when displaying the GridView (for example in the OnRowDataBound), because I want to access the fields inside JobInstance for each cell to determine formatting options, and add other links in each cell.
I use a repeater on my website.My code for this example is
<ItemTemplate> Item: <%#DataBinder.Eval(Container.DataItem, "Col")%><br> </ItemTemplate>
I'm working against a database that wasn't designed by me and in all the tables there is a CreatedBy field that is an int. Now when I generate against this db i get all kinds of errors because subsonic is expecting that field to be a varchar.
I don't particularly want to go and rename the field in all of these tables so I was hoping there was a way to "alter" or change the internal convention (without getting into the source) in subsonic.
Has anyone been able/done this in subsonic 3.0.4??
EDIT: I'm using the active record model in subsonic 3
I have my gridviews, buttons and labels put into tables:
[URL]
Here is how the page looks when I run it:
[URL]
Then when I select an Order this happens:
[URL]
Why is it when I select an Order and the second gridview pops up theat it moves my text and Ship button down? I thought I had it setup in the tables so this wouldnt happen?
I am using a gridview with sqldatasource. How to get back the datasource in the codebehind ?
View 2 RepliesI have a List of complex objects containing other objects within that I give as the data source to a gridview.(currently I'm using BoundFields for the columns). I need to bind data to the columns from the objects within at run time. How can this be done?
View 1 Replies