C# - Get Field Descriptions From A Parent Related Table In A Gridview
Aug 6, 2010
What would be the best way to set a gridView.DataSource for LINQ query with some foreign keys and get fields in the parent tables? Like this:
The table BOOK have a Author_Id, which is related to table Author
class:
public IQueryable<Book> ListAll()
{
RENDBDataContext db = new RENDBDataContext();
var result = from b in db.Books
orderby b.Id descending
select b;
}
code-behind:
grdBooks.DataSource = vBooks.ListAll();
grdBooks.DataBind();
In the ASPX page I can get to the Author name with the [asp:TemplateField], using <%Eval("Author.Name")%>
What I'm looking for is a better solution, that doesn't involve changes in the aspx page
View 1 Replies
Similar Messages:
Jun 10, 2010
i have a GridView bound to a DataView. Some columns in the DataView's table are foreignkeys to related tables(f.e. Customer). I want to enable sorting for these columns too, but all i can do is sorting the foreignkey(fiCustomer) and not the CustomerName.
I have tried this without success(" Cannot find column ERP_Customer.CustomerName "):
<asp:TemplateField HeaderText="Customer" SortExpression="ERP_Customer.CustomerName" >
A tried also the DataViewManager, but i've a problem to detect the table to sort:
[code].....
I have to apply the sort on a distinct table of the DataViewManager, but this table would differ on the related tables.
I have bound the TemplateColumns in Codebehind in RowDataBound-Event f.e.:
Dim LblCustomer As Label = DirectCast(e.Row.FindControl("LblCustomer"), Label)
LblCustomer.Text = drCharge.ERP_CustomerRow.CustomerName 'drCharge inherits DataRow
What is the recommended way to sort a GridView on columns related to other tables? I could build a custom datatable with the customername instead of the foreignkey and bind this column to the TemplateField. But then my huge dataset in the model makes no sense anymore.
EDIT: I have a model with a Dataset. I'm binding one Datatable(ERP_Charge) from it to my GridView(actually i take a Dataview from that Table). In this Datatable are columns that are related to other Datatables in the Dataset(relations are defined). When i want to make the grid sortable its no problem on the columns that belong to ERP_Charge.
But the columns with foreign keys to other table could not be sorted because the Gridview shows f.e. not the CustomerID but the Customername. I get the Customername in RowDataBound. Normally i would join the tables and add a Datacolumn for the Customername.
View 1 Replies
Jan 19, 2010
I have a basic CMS which I'm adding to a site to display some downloads organised into groups. I have two tables, one for the groups and one for the downloads. I'm using a repeated to display the groups with another repeater inside to display the children. This works perfectly.
However some of my download groups may not have any downloads related to them and I'd like to handle this by filter the groups so that only those with a relate download record(s) are shown.
I'm trying to do this with the query which populates the top repeater based on some ideas I read but I must be going wrong with the syntax.
Here is what I'm using to try and only select downloads groups which have downloads linked to them by the download group ID.
[Code]....
Can anyone offer any thoughts on how I should construct the query to perform this?
View 1 Replies
Feb 23, 2011
I am using an ADO Entity Model for my ms-sql database.
My database has a Resellers table which has ResellerID (primary key, int) and Name columns along with other data.
I also have an Orders table which contains OrderID (primary key, int), OrderDate, ResellerID (foreign key to Resellers.ReselerID).
If I just do a query like:
[Code]....
I am able to reference order.Reseller.Name just fine with no problems.
However I have an EntityDataSource on my page as follows:
[Code]....
Notice the Include="Reseller" attribute in the datasource... I also have a GridView tied to that datasource as follows: I cut some of it off for breavity:
[Code]....
Now what I have listed above will run with no errors, but what I want to do is replace the column that displays "ResellerID" with the equivilant to order.Reseller.Name. In other words I want my grid to display the reseller's name rather than the numeric ID.
I have tried to change the DataField to "Reseller.Name" but that will generate the following error:
A field or property with the name 'Reseller.Name' was not found on the selected data source.
Is there anyway to do this without me writing a custom select statement in my code behind?
View 2 Replies
Aug 18, 2010
I've got a gridview that is databound with LINQ in the code behind. One column shows the id from the table. I would like to show a more human friendly product name that is associated with that id number but is from another table. Thought I had it figured out by entering a Template field in the gridview tags (in the .aspx page) and an item template within that with
<ItemTemplate>
<%Eval(Products.productName")%></ItemTemplate>
but when I try to build it says this can only be done in the context of a databound control.
Can I add this column within the gridview tags or does it have to be done from the code behind?
View 3 Replies
Jan 21, 2010
I have a table named RECIPE which is linked to an other table name RECIPE_STATUS
In RECIPE table I have a field named Status_Id which contains the name of the Status which is fetch from the RECIPE_STATUS table based on this ID.
The RECIPE table sample information are as follow :
ID Name Status_Id
====================
1 Test1 0
2 Test2 1
3 Test3 2
The RECIPE_STATUS entries are as follow:
ID Name
========
0 Locked
1 Running
2 Free
From an ASP.net page I would like that my user is capable of changing the RECIPE_STATUS from a given recipe. For that I have a DataGrid which is bind to the RECIPE table.
But then what I would like is that the STATUS shown to my user to be the name Locked,Running or free depedning on the Id
How can I bound in my Datagrid the Recipe.Status to be bind to RECIPE_STATUS.Id ?
IN addition to that, If my user change the status for a given recipe, it should be properly save.
View 1 Replies
Aug 5, 2010
I need to display a set of linkbuttons(nearly 30)with different descriptions.
when i click on a linkbutton an associated querystring(which is not description)is supposed to be copied to a textbox.
View 2 Replies
Jan 18, 2011
I have 2 tables:
User(Id PK, TitleId FK, Name, Active)
Title(Id PK, Text)
Title is a lookup table of titles (Mr, Miss,...) and its got a relationship with table User by TitleId.
Now I'm trying to display the data in a web page using .net and Entity Framework. I'm using a ListView control and a query as a source. it all displays fine except for the Title.
Here is my code:
MyEntities _entities = new MyEntities (); User user = new User(_entities); IQueryable u = (from x in _entities.Users where x.Active == true select x); ListView1.DataSource = u; ListView1.DataBind();
and the code in the front end:
<asp:ListView ID="ListView1" runat="server" EnableModelValidation="True" DataKeyNames="Id"><ItemTemplate> <tr> <td> <%# Eval("Id") %> </td> <td> <%# Eval("Title.Text") %> </td> <td> <%# Eval("Name") %> </td> </tr></ItemTemplate><LayoutTemplate> <table ID="itemPlaceholderContainer" runat="server"> <tr runat="server"> <th id="Th2" runat="server"> Id</th> <th id="Th1" runat="server"> Title</th> <th id="Th3" runat="server"> Name</th> <th runat="server"> </tr> <tr runat="server" ID="itemPlaceholder"> </tr> </table></LayoutTemplate>
How do I manage to get the Title Text associated with a User to display on the ListView?
View 4 Replies
Mar 30, 2010
I have a strongly typed view for Contacts table In my index page , i am accessing the tables as --- "foreach (var item in Model)"
This table has an association with Groups Table
How can i access Groups table data from view.
intellisense gives me possibility to write like "item.Groups.GroupTitle"
But it returns null(object not initiated) How to solve this?
View 3 Replies
Nov 7, 2010
I've always been a bit unsure how to check for the existance of properly referenced table data.
In my situation I have various tables related to each other in many-to-one relationships where the "1" side can be deleted without the reference fields on the "many" side being updated (nulled).
I have FK relationships set up in my MS SQL server database but have turned off the FK constraint enforcement (and cascading update/delete) so that I can delete records from the "1" side but leave the keys for those deleted records in the records on the "many" side. This is something I really need to do for my web app design.
View 1 Replies
Jan 29, 2010
I want to sum my nested gridview column totals in parent grid's footer.
View 4 Replies
May 17, 2010
I want to get record count from below example.
I made two tables. One is club_info and another one is club_members.
And each table has data like following
[club_info]
club_id
club_name
:
[club_members]
mem_id
club_id
:
I want to get club_name and the member count for selected club_id and want to return the result as sqldatareader.
View 8 Replies
Jun 8, 2010
My dataset table data is from multiple tables (showing on a gridview),How to update the database tables using batch udpate on clicking submit, if the data is from a signle table, no problem, but I am not sure how to handle if the datais from mulitiple tables? If I have related tables, do I need put them in differet tables in the dataset?
View 6 Replies
Mar 21, 2010
I've created a membership system based on asp.net 2. There are other tables that store user information, such as emails sent etc. I've created a users table based on the TableProfileProvider. My question is concerning deleting the member
Is it OK to delete the member from the aspnet_membership table and roles related tables using Membership.DeleteUser, though keep all the custom tables and the information including the information in the Users table created by the TableProfileProvider? or can you foresee problems?
View 1 Replies
Apr 21, 2010
I'm pretty new to MVC 2 using the Entity Framework. I have two tables Company {ID int identity PK,Name nvarchar} and User {ID int identity PK,UserName nvarchar,CompanyID int FK}. A Foreign Key exists between User and Company.I generated my ADO.NET Entity Data Model, a Controller and a view to insert a record. My HTML form has the fields Company and UserName and the is when I click save a Company and User is inserted into the database. Sounds straight forward right!
My question is as follows:
I created a strongly-typed view derived from my 'User' entity. I'm using the the html helper Html.TextBoxFor(model => model.Organisation.Name) but the html name attribute for this input field is 'Organisation.Name'. My problem with this is that the dot throws up all sorts of issues in JQuery, which sees this as a property. If I want to change the name I read that I can use DataAnnotations but because I used the Entity Designer this involves using Buddy Classes. Seems like a bit of overkill just to change the html name attribute on this input field.
View 1 Replies
Nov 19, 2010
I need to write a query to populate a gridview with minimum rates in ascending order for a month from three tables.For example i have three tables A,B,C as follows
TABLE A TABLE B
TABLE C
Id id id
Quote_no Quote_no Quote_ no
Name Rate1 Equip_name
Rate2 E_rate
Date R1_rate
R2_rate
Date
Now if the data is as follows
I need to get the Name from Table A ,minimum Rate1 and Rate2 values for a month in a dropdownlist from date field from Table B and the corresponding minimum rate(E_rate) for Equipment E1 and E2 only from Table C for the month in ascending order group by Name.
TABLE A
id
Quote_no
Name
1
101
XYZ
2
102
ABC
TABLE B
id
Quote_no
Rate1
Rate2
Date
1
101
105
200
12/11/2010
2
102
90
210
15/11/2010
TABLE C
id
Quote_no
Equip_name
E_rate
R1_rate
R2_Rate
Date
1
101
E1
60
0
0
12/11/2010
1
101
R1
0
110
0
12/11/2010
1
101
E2
80
0
0
12/11/2010
2
102
R2
0
0
300
15/11/2010
2
102
E2
100
0
0
15/11/2010
2
102
R1
0
60
0
15/11/2010
2
102
E1
230
0
0
15/11/2010
View 9 Replies
Feb 27, 2010
my gridview binds to a datatable and i added a template field to the columns the template field contains a link button. i bind the command argument of this link button to a field from my data table. on the row command event i allow the user to activate his product according to a condition. what i want is how to add a javascript alert if the condition doesn't match. in other words i can't call the hyperlink in the templatefield in order to add a javascript to its OnClientClick attribute.
View 8 Replies
May 25, 2010
I have a gridview which I have databinded via the quick config facility, but I need to databind one column to a completely different sql table data field - how do I do this?
If I go into Gridview tasks and select the column and edit the data binding parameter but what is the format for a table outside the source definition for the the rest of the gridview?
View 4 Replies
Jan 10, 2011
I have a parent control that has an instance of a HiddenField child control. I am using CreateChildControls() to add it. Everything works client side including the values being added to the field. However, on postback, the reference to the field is null
here is the code
[code]....
I have tried simply relying on the ViewState ... then also attempted using FindControl(). Neither works, it comes up as a null reference ... any input on what is going here?
View 2 Replies
Jun 11, 2010
I want to hyperlink from a field in one gridview to a field in another gridview based on id. I've tried many ways but haven't seen success.
View 20 Replies
Mar 30, 2010
I have- empId - PK, CurrentUserId in one table,mpId- FK in other table.now i want to get empId of related currentUserId ,and want to add empId in other table having FK,using Repository,what will be in create method?
View 4 Replies
Feb 26, 2010
I have a table that needs sorting by its hierarchial structure of parent-child.
An example of my table is below
ID
Name
Parent ID
Sort Order
1
iPhone Dev
0
1
2
iPhone Lounge
0
2
3
Web Development
0
3
17
Javascript
3
1
24
CSS
3
2
25
prototypes
17
1
As you can see above, my table structure follows this pattern
[Code]....
My overall aim is to have the sql order the table for me, and by using this new "depth" column, I will be able to indent by categories in the menu on the front end, you have probably seen this before, but all the tutorials I have read dont really explain it very well, or assume you are sql savvy.
View 2 Replies
Jun 4, 2010
I would like to display students and their grades with a GridView and LinqToSQL like this:
assignment1 assignment2
Student 1 55 89
Student 2 87 56
Student 3 92 34
I have a many-to-many relationship between students and assignments called "grades". The grade for the assignment is stored in that table in a "gradeNumber" column.
I would also like to specify which assignments should be displayed in the grid. Btw, my LINQ entities are extended to allow me to write/get studentx.Assignments or assignmentx.Students.
View 1 Replies
May 13, 2010
a table with related records (above is showing tapes, with different shots on the tapes). I already have the tapes data with the URLs working so not worried about that - just how to show the related information. Doesn't have to be exactly like this - but all the information must be visible at the same time ie no click to view or hover over.
View 2 Replies
Jul 13, 2010
I'm trying to update the data in the parent table that is referenced in the child table from the child's view in Asp.net.
I mapped the tables using Fluent Nhibernate.
In the child table, the mapping looks like this:
[code]....
View 1 Replies