In my project there are two tables (Users & Roles). I'm using Dynamic Data (Code-Behing VB.Net). In my existing code when i click on the Insert Link it takes me to the page which has got two DropDownLists (Roles & Users). In my users DropDownList i could
just see the Forename of the Users. I also want Forename & Surname together in the same control. I tried most of the things, but nothing happened. Can anyone please help me out in solving the problem with some information about it.??
Thanks for the reply. As I'm new to Dynamic Data, So, I am not been able to figure it out, where to make the changes and do i need to add any new aspx page in the project. I'm sending you the code & the screen shots. Please Help....
So, the above are the screen shots. Now, where should i change and what should i change??
I have used ADO.NET Entity Data Model which has generated an .EDMX file automatically, therefore I didn't write any SQL. This scaffolding automatically resolves PK/FK relationships and substitutes the IDs/PK of parent table with another more descriptive
column. In my case, when I view the Orders (child) table, it shows me the FirstName field from Customers (parent) table instead of the PK which is CustomerID.
Now I would like to see the full name of a customer instead of the FirstName. I have seen some posts which describe how to do it using a Literal control but I want to know how do we populate dropdown lists. In ForeignKey_Edit.acsx.cs, a method PopulateListControl()
is called on Page Load event which is probably doing all the stuff I am after but I cant find a way to override it. Or may be there is another way to do this.
Hi Samthapar, the solution I mentioned above is the only one that works for DD with ADO.Net Entity Framework. you will need to create your buddy classes for Metadata and then override the ToString method of the Entity to get the desired result.
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
Thanks for the reply. I have tried that one. But the issue here is i have to fetch the Surname from the different table and I'm not been able to find out the possible solutions for the same. If you have any clue please let me know, it would be a great help.
Now, I want to display the Forename + Surname in User DropDown. I added a class file with the name UsersInRole.vb and the code is below:
<MetadataType(GetType(UsersInRoleMetaData))> _
Partial Public Class UsersInRole
<UIHint("UserInRole_Enumeration")>
Public ReadOnly Property FullUserName() As String
Get
Dim x As String = Me.User.Forename & " " & Me.User.Surname
Return x
End Get
End Property
End Class
<DisplayName("User in Roles")> _
Public Class UsersInRoleMetaData
'<UIHint("UsersInRole_ForeignKey")>
'Public FullUserName As Object
End Class
I tried most the things you mentioned, but when i try to access the Surname, it says "Property not found in UsersInRoles".
Can you please tell me, where am I doing the wrong. I mean I am really confused about it, where to make the changes and which new file should I add. Can you please send me some solution with structure. It would be a great help.
Member
2 Points
16 Posts
Problem in Populating DropDownList with two Columns of a Table using Dynamic Data with VB.Net
Feb 03, 2012 05:38 PM|Samthapar|LINK
In my project there are two tables (Users & Roles). I'm using Dynamic Data (Code-Behing VB.Net). In my existing code when i click on the Insert Link it takes me to the page which has got two DropDownLists (Roles & Users). In my users DropDownList i could just see the Forename of the Users. I also want Forename & Surname together in the same control. I tried most of the things, but nothing happened. Can anyone please help me out in solving the problem with some information about it.??
Member
30 Points
29 Posts
Re: Problem in Populating DropDownList with two Columns of a Table using Dynamic Data with VB.Net
Feb 03, 2012 05:47 PM|sivakumar321|LINK
Post your problem code ,screen shots.
use concatenation(+) funtion in sql to combine to fields of the table and bind it to the dropdown.
select 'Forename'+' '+'Surname',
All-Star
17915 Points
5679 Posts
MVP
Re: Problem in Populating DropDownList with two Columns of a Table using Dynamic Data with VB.Net
Feb 04, 2012 09:27 AM|sjnaughton|LINK
You can override the ToString method of the entity to do that see Rick Andersons article here Improving the FK field display: Showing two fields in Foreign Key columns
Always seeking an elegant solution.
Member
2 Points
16 Posts
Re: Problem in Populating DropDownList with two Columns of a Table using Dynamic Data with VB.Net
Feb 06, 2012 05:45 AM|Samthapar|LINK
Hi SivaKumar
Thanks for the reply. As I'm new to Dynamic Data, So, I am not been able to figure it out, where to make the changes and do i need to add any new aspx page in the project. I'm sending you the code & the screen shots. Please Help....
So, the above are the screen shots. Now, where should i change and what should i change??
Thanks
Member
2 Points
16 Posts
Re: Problem in Populating DropDownList with two Columns of a Table using Dynamic Data with VB.Net
Feb 06, 2012 05:48 AM|Samthapar|LINK
Hi,
I have used ADO.NET Entity Data Model which has generated an .EDMX file automatically, therefore I didn't write any SQL. This scaffolding automatically resolves PK/FK relationships and substitutes the IDs/PK of parent table with another more descriptive column. In my case, when I view the Orders (child) table, it shows me the FirstName field from Customers (parent) table instead of the PK which is CustomerID.
Now I would like to see the full name of a customer instead of the FirstName. I have seen some posts which describe how to do it using a Literal control but I want to know how do we populate dropdown lists. In ForeignKey_Edit.acsx.cs, a method PopulateListControl() is called on Page Load event which is probably doing all the stuff I am after but I cant find a way to override it. Or may be there is another way to do this.
Please help me
Many thanks
All-Star
17915 Points
5679 Posts
MVP
Re: Problem in Populating DropDownList with two Columns of a Table using Dynamic Data with VB.Net
Feb 07, 2012 12:41 PM|sjnaughton|LINK
Hi Samthapar, the solution I mentioned above is the only one that works for DD with ADO.Net Entity Framework. you will need to create your buddy classes for Metadata and then override the ToString method of the Entity to get the desired result.
Always seeking an elegant solution.
Member
2 Points
16 Posts
Re: Problem in Populating DropDownList with two Columns of a Table using Dynamic Data with VB.Net
Feb 08, 2012 05:14 AM|Samthapar|LINK
Hi Sjnaughton
Thanks for the reply. I have tried that one. But the issue here is i have to fetch the Surname from the different table and I'm not been able to find out the possible solutions for the same. If you have any clue please let me know, it would be a great help.
Thanks
All-Star
17915 Points
5679 Posts
MVP
Re: Problem in Populating DropDownList with two Columns of a Table using Dynamic Data with VB.Net
Feb 08, 2012 05:27 AM|sjnaughton|LINK
I would look at using a computed column and a scaler valued function to retrive the value in the DB.
Always seeking an elegant solution.
Member
2 Points
16 Posts
Re: Problem in Populating DropDownList with two Columns of a Table using Dynamic Data with VB.Net
Feb 13, 2012 12:06 PM|Samthapar|LINK
Hi Sjnaughton
I have two tables User & UsersInRoles
User Table has got:
UserID
Forename
Sirname
etc.
UsersInRoles has got:
UsersInRolesID
UserID
RoleID
(Just 3 Columns)
I have two dropdowns
Role : Readonly/Admin/Edit
User: John/Harry/Chris
& the path is /UsersInRoles/Insert.aspx
Now, I want to display the Forename + Surname in User DropDown. I added a class file with the name UsersInRole.vb and the code is below:
<MetadataType(GetType(UsersInRoleMetaData))> _
Partial Public Class UsersInRole
<UIHint("UserInRole_Enumeration")>
Public ReadOnly Property FullUserName() As String
Get
Dim x As String = Me.User.Forename & " " & Me.User.Surname
Return x
End Get
End Property
End Class
<DisplayName("User in Roles")> _
Public Class UsersInRoleMetaData
'<UIHint("UsersInRole_ForeignKey")>
'Public FullUserName As Object
End Class
I tried most the things you mentioned, but when i try to access the Surname, it says "Property not found in UsersInRoles".
Can you please tell me, where am I doing the wrong. I mean I am really confused about it, where to make the changes and which new file should I add. Can you please send me some solution with structure. It would be a great help.
Looking forward to hear from you soon.
Thanks