VS 2010 GridView - Show 'pretty Name' Of Class Property?
Jan 10, 2011
I have a class Person that represents a person in my database. This class has a CategoryId property (int) and a Category property (type Category).
Category is a class that represents a category in my database. csharp Code:
public class Person{ public int Id {get; set;} public string Firstname {get; set;} public string Lastname {get; set;} public int CategoryId {get; set;} public Category Category {get; set;}} public class Category{ public int Id {get; set;} public string CategoryName {get; set;}}
[code]....
I am displaying a list of these Persons in a GridView, and I would like to display the name of the Category (the CategoryName property to be precise). So I define this markup;
xml Code:
<asp:GridView runat="server" ID="personsGrid" AutoGenerateSelectButton="True" AutoGenerateColumns="False" DataKeyNames="Id"> <Columns> <asp:BoundField DataField="Id" HeaderText="Id" /> <asp:BoundField
Usually I would solve this problem by one of two ways:Override the ToString method of the Category class and return the name.
Add a readonly 'CategoryName' property to the Person class, where I return 'this.Category.CategoryName' (and then bind the column to this property instead).
In this case however, I am using the Entity Framework, and the Person and Category classes are automatically generated by the database model. I suppose I could edit the generated code manually, but I don't like that, since any change in the model will cause VS to re-generate the code and my changes would be lost. So these two methods are not going to work...
The simple question remains: how do I make the Category column show the CategoryName property of the object it represents, rather than just the type name?In a DropdownList for example (which I am already using for the user to select a category when creating a person), I can set the DataTextField (to "CategoryName") and DataValueField (to "Id") properties and it displays the right name and uses the right value (the Id). I can't find anything similar for a BoundField though... Am I overlooking something obvious?
Another solution would be if I could tell the Entity Framework model to add another property to my Person class which returns the CategoryName of the Category. I can't find any way to do that though (I am a compleet noob in EF),
View 5 Replies
Similar Messages:
Jul 14, 2010
i have created a new user control who contains a gridview so, my prolem now is that i want show all the property of the gridview included in the control, but i want not write like this:"Usercontrol1.GridView1.Datasource=...." but i want write "Usercontrol1.DataSource=..." and this also for other controls how can i do this?
View 1 Replies
May 21, 2010
Is it possible to use InvokeMember() of Type class to call a property of a property of a class?
[Code]....
View 1 Replies
Apr 18, 2010
When I open an ASP.NET 3.5 project using VWD2010, I get a prompt error message,"The connection property in the web.config file is missing or incorrect.The connection string from the .dbml file has been used in its place."however, my project works successfully.
View 1 Replies
Jul 12, 2010
am using class diagram of visual studio 2008as you can see the image i need show to user that the period and calendar classes have the idMarket property that refers to market classhow can i do this?
View 1 Replies
Feb 24, 2010
Can anyone tell me how to show alert message inside the .cs file of class library project in c#? I am calling a method of cs file in classlibrary project. Whenever the control comes to the alert message statement inside the method, alert message should be shown on the web page(aspx) and the next statement to the alert message statement should not be executed.
View 3 Replies
Nov 12, 2011
When I click the Edit button in Gridview twice it'll always show the edit box or (textbox in gridview are editable)how to prevent that?
View 4 Replies
Mar 25, 2010
How do i get the pretty URL with an ASPX pages. I have listed a couple links below and their associated print page url. As you can see it resembles the Class instantiation method of declaring object but is used for a webpage with its extension.
I was wondering if this method can be used or if this is a URL rewrite to mask all the querystrings and sub directories being referenced. I remember doing stuff like this when i was working on a UNIX system using the .htaccess file to mask effective query
string being shown. I believe they called it a Clean URL, i maybe wrong as it has been well over 8 years since i dealt with the Unix .htaccess file and massaging urls with it.
For instance, look at the MSDN site pages:
http://msdn.microsoft.com/en-us/library/system.servicemodel.actionnotsupportedexception.aspx
Now when you want to print it:
http://msdn.microsoft.com/en-us/library/system.servicemodel.actionnotsupportedexception(printer).aspx
Now you select the same page but choose a different framework than its birth:
http://msdn.microsoft.com/en-us/library/system.servicemodel.actionnotsupportedexception(VS.100).aspx
and the print URL:http://msdn.microsoft.com/en-us/library/system.servicemodel.actionnotsupportedexception(VS.100,printer).aspx
As you can see they are not visually passing query strings but more like Class parameters. Is this just a simple URL rewrite after the page is loaded so the user doesnt see the query string information?
View 3 Replies
Mar 16, 2011
how to getValue of property class with this method?
public static int SQLInsert<TEntity>(TEntity obj) where TEntity : class
{
foreach (var item in obj.GetType().GetProperties())
{
//item.GetValue(?,null);
}
return 1;
}
View 3 Replies
Feb 10, 2010
I'm exporting a PDF report from Crystal Reports bundled with VS2008. I need to display non-standard fractions so that they look nice instead of just something like 26/32. I have turned html interpretation on for the field so ˝ and other standard html entities display nicely, however, because CR does not understand <sup> and <sub? I cannot format non-standard fractions to look pretty.
View 1 Replies
Apr 12, 2010
The Html.ActionLink
<li> ${Html.ActionLink<HomeController>(c => c.Edit(ViewData.Model.Id, ViewData.Model.Title), "Edit")} </li>
When created as html shows the URL to be Edit/5006?title=One . How do I change this to a pretty URL like Edit/5006/One ?
My Edit Action method is,public ActionResult Edit(int id, string title)
View 3 Replies
Jul 21, 2010
I am applying css style to "body" and to a div which id is "overlay" like:
body
{
margin:0;
[code]....
"overLay" div is inside noscript tag which renders in the browser only when javascript is disabled in the browser.My requirement is that I have to set "overflow:hidden" in the body when "overLay" div get rendered.
View 2 Replies
May 11, 2010
I have a class, let's say class Sample. Sample has unknown properties but inherits an interface ISample. Said interface includes one method which I'm trying to create. This interface has a method called getPropertyValue(object o, string PropertyName).
It returns the value of the o.PropertyName using generics (unless you have a better suggestion). How do I write it? In other words, I want to be able to pass the name (as a string) of a property and return its value. Samples in C# preferrable but VB ok and any comments or suggestions are welcome.
View 2 Replies
Feb 25, 2010
we have a program that we work with with in 2 different locations, both of the program instances must share the same database.what i did is to open Web Sharing folder on our server then i added on both computers this folder to their "My network places" and direct both of application to this folder which contains the database.this is how i direct the program :
Code:
D:WNKKWnkk.exe \MyServerktest
nk2008
it all works fine but there is one problem, the data pulling is pretty slow when it shouldn't we have 100MB download / upload on our server and over 10MB dl/ul in our office.
some pointers:i added the shared web folder to one of our website directory and thats mean that the port the program is using is 80
is port 80 is slower then others?
View 10 Replies
Mar 5, 2010
I have an asp.net app consisting of about 15 aspx pages and 30 or so user controls. For the most part it is just a basic CRUD layer on top of a database, so it consists mainly of edit forms and datagrids.
All of my edit forms are laid out in fieldsets, and I am using plain asp:GridViews for my tables (they render to an html table). Some forms are in serious need of tabs to lay out the elements. I'd really like to be able to style my GridViews with a fixed header and vertical scrollbars.
I have to do a demo in a few days but the problem is, there is no styling whatsoever applied to the html (no classes defined within the html, no CSS at all), and I am very weak with CSS.
So considering my predicament, can anyone offer some advice on how I could get this looking presentable in a very short period of time?
Is there such a thing as pre-existing decent generic CSS files I could download and drop on top of this app that could apply an attractive and consistent look and feel to most elements? Would http://jqueryui.com/ be useful in this particular situation?[URL] looks very attractive, can anyone comment on how easy it would be to globally wire all of my GridViews up with that?
View 3 Replies
Jun 12, 2012
I have several controls on a page that I want to bind the enabled property to a couple of properties in code behind that are set on Page_Load. Here's an example of what I'm using to bind to the properties.
Code:
<telerik:RadComboBox ID="AssignToRadComboBox"
runat="server"
[code]...
This works fine once the page is posted back for the first 4 controls on the page.Here's the 1st control that doesn't get disabled like I expect it to. The expression is the same in the Enabled property so I'm not sure why it isn't working.
Code:
<telerik:RadComboBox ID="CategoryRadComboBox"
runat="server"
Skin="Web20"
Width="225px"
Enabled='<%# IsAdmin && !IsCompleted %>' />
I've got 2 problems with this approach:
1. I need it to happen the first time the page is loaded rather than after a postback.
2. I need it to work for all of the controls on the page having the expression.
It's too late in the development process to rewrite the page so I can't use jQuery & knockoutjs for example to do this all on the client side.
View 2 Replies
Oct 8, 2010
I have a class called Questions. This Questions has properties QuestionID and QuestionAnswer. My list of Questions has QuestionID like 2,3,4,15,12,24,22,,,, etc I need to sort this List of Questions Object based on QuestionID and store in another Questions object.
View 2 Replies
Oct 29, 2010
Actaully i am careted one webservice name:service1,created one more class name: service2 this poperty class for webservice,My question is
1.How to access that property class in client side?
2.It's possible to create Layer archt. Inside the webservice?
View 4 Replies
Jan 18, 2011
If i want to use Property & Method in same class then how to use it. I want to keep separate class only for interface , not for property.
Also we have tried with [OperationContract] before get ,set in Service class . it solved our issue but throws error while run a .svc file
View 1 Replies
Feb 21, 2011
I have question about HttpContext class (http://msdn.microsoft.com/en-us/library/system.web.httpcontext.aspx). This class has Responseproperty (http://msdn.microsoft.com/en-us/library/system.web.httpcontext.response.aspx). But I don't understand, why Response property hasHttpResponse return value, not HttpContext (this is HttpContext, not HttpResponse property).So, why there is:
[Code]....
not
[Code]....
View 3 Replies
Feb 20, 2015
I am working on a page whereby all the controls within the page get translated to another language.
This is handled within the master page prerender event and generally works fine.
However my page consists of a multiview control that is made up of 2 views. By default the INSERT formview is displayed so the user can enter form detials. This translates fine.
On clicking the save button the multiview active index is set to 1 and the EDIT formview displayed so as the user can update any of their details. This view does not get translated.
It would seem this is due to the controls not being available at this point in the page cycle or when this button event fires.
So i opted to do the translate process within the prerender event of the EDIT formview, and the method does have access to all the controls within this formview and runs after the master page prerender event. So all should be good.
However it seems that all th epage properties at this point in time are cleared. So the translation doesnt work. At the point of master page prerender i have verified they are populated with the values, but as soon as i hit the formview prerender all the page properties get cleared to nothing...
View 2 Replies
Nov 27, 2011
When I add a user control which has bindable properties to an asp.net page I do not see its bindable properties on the designer's dialog box when I click the edit Data bindings on the Repeater-Listview
Code:
Imports System.ComponentModel
<System.ComponentModel.DefaultBindingProperty("Text")> _
Public Class UserControls_ucSpecialTextBox
Inherits System.Web.UI.UserControl
...
<EditorBrowsable(EditorBrowsableState.Always), _
[Code] ....
View 6 Replies
Dec 6, 2010
What am I doing wrong here?
Me("Label" & CStr(i)).Text = strURI.Substring(strURI.ToString().LastIndexOf("/") + 1) & ": " & intCount.ToString()
[Code]....
I get an error on Me; it indicates that it cannot be indexed because it has no default property
View 5 Replies
Oct 3, 2010
I have a vb class that reads a single row of data from an SQL view. I want to add a property to it that will expose the value of a new bit field. But whatever I do my class always returns the value "false".What am I doing wrong?
Public ReadOnly Property IsPublished() As Boolean
Get
Return valPublished
End Get
End Property
Here's the relevant line from my datareader: Me.valPublished = Convert.ToBoolean(theObjectReader("Authorised"))Authorised is my bit field. I have tried it with and without the "ConvertToBoolean" statement.When I response write the value of the property for rows where this field is true, it always shows false.
View 4 Replies
Feb 21, 2011
Why doesn´t this property return a datetime formated with the following pattern when using the property in the codebehind page in my ASP.NET Webforms website? When debugging i can see that the value the returning datetime is "2011-02-21 16:13:29.670" wich is correct.
[code]....
And after assigning the returned property value to a hiddenfield in the .aspx page i get this value assign to the hiddenfield.value "2011-02-21 16:13:29"
hdnUserLastUpdated.Value = objUser.UserLastUpdated
View 1 Replies