Web Forms :: Dropdownlist DataBind Using Strongly Typed Property For DataTextField?

Aug 13, 2010

I would rather not magic string my DataTextField/Values on the dropdownlist after setting up the source as a List collection of objects.

I was thinking I could use the DataSource properties but it doesn't seem to like the couple of ways I tried.

WORKS BUT NOT IDEAL
//set the datasource to the returned List<Cart>
this.cartDdl.DataSource = CartManager.Load(WebProfile.Current.UserName);
//set the DataValueField to the Cart.ID property
this.cartDdl.DataValueField = "ID";//would rather use the obj property Cart.ID
//set the DataTextField to the Cart.Description property
this.cartDdl.DataTextField = "Description";//would rather use the obj property Cart.Description
//Bind the ddl to the datasource
this.cartDdl.DataBind();
HOW I WOULD THINK IT COULD WORK this.cartDdl.DataValueField = ((Cart)this.cartDdl.DataSourceObject).ID; this.cartDdl.DataTextField = ((Cart)this.cartDdl.DataSourceObject).Description;

View 2 Replies


Similar Messages:

MVC 2 - Add A Default Property To A Strongly Typed Html.Textbox Helper

Apr 22, 2010

The strongly typed helpers are now written like this -

<%= Html.TextBoxFor(model => model.State) %>

I need to add a default value to a textbox. In the prior version of Asp.Net MVC it was easy to assign a default value. I thought doing the following would work in MVC 2-

<%= Html.TextBoxFor(model => model.CountyId, new{ value = 840 })%>

This, however, does not work for me in Asp.Net MVC 2. The value is still blank for the textbox. I want to make sure that this isn't some random error that I am having. Has anyone else encountered the same problem? I have searched and searched to find more information on the default property for the html helpers in MVC 2, but I can't find anything. Does anyone out there know how to correctly assign a default value to a textbox in Asp.Net MVC 2?

View 3 Replies

C# - MVC Strongly Typed View With DropDownList

Jul 6, 2010

Long story short, I'm trying to add a few extra items to ViewData to make my life easier, and its an edge case that doesn't really justify its own model just for this one case. Keep reading for more specific details.

So I have a strongly typed edit view for one of my objects, everything works great until I try to put a dropdownlist on the view with an ID that does not match a property of my class.

I have this

[code]....

My expectation is that in the controller action that accepts the POST, I will manually use the FormCollection[] to read out that ID and populate MyOtherModel with the correct ID.

View 1 Replies

Binding Dictionary To DataTextField Property Of DropDownList

Oct 29, 2010

I have a State class defined like this:

Public Class State
Public Property StateId As Integer
Public Property Name As Dictionary(Of Integer, String)
End Class

Name(x) contains the state name in different languages. I get a collection of State from the method StateManager.GetAllStates() and I want to bind this collection to a DropDownList. The problem is that I can't find how to set the DataTextField property to let's say stateList.Name(1) which is the english name of my state.

Dim stateList As StateCollection = StateManager.GetAllStates()
Me.DataSource = stateList
Me.DataValueField = "StateId"
Me.DataTextField = "Name(1).Value" <-- Problem here
Me.DataBind()

View 2 Replies

Strongly-typed Or Weakly-typed Binding In Codebehind In Front End?

Feb 23, 2010

So my question is more in relation to what people consider to be the best practice and why:

I've been dropping literals into pages and repeaters and binding them in code behind for a while. Is this considered bad practice?

ie:

ASPX Page:

<asp: Literal id="litTextToInsert" runat="Server" />

Code Behind:

litTextToInsert.Text = objData.MyText;

OR (repeater):

[code]....

I personally dont like doing this as i find it makes it harder for me to know if someone changed the field name, or mis typed it during development - the other way you won't know until the page loads.

With the strongly typed version if something changes in your DAL etc the build will break - letting me know I've messed up.

Why do so many people appear to use weakly typed code in ASP.Net (in examples, MVC, etc)?
Am i missing something?

View 2 Replies

MVC Strongly Typed Versus Dynamically Typed Views

Nov 25, 2010

Given the benefits of using strongly typed views to eliminate typed errors and the use of lambda expressions why would one use a dynamically typed view? When I use them I don't feel as safe as with strongly typed views. Am I missing something? Is there a special use for them?

View 2 Replies

Mvc - Get Strongly Typed From String

Jan 18, 2010

My error code:

string model = "Content";
Type stype = Type.GetType("mvc.Models." + model);
ViewPage<stype> vp = new ViewPage<stype>();

Of course it error when compiling, but it clearly show what i'm thinking.

View 1 Replies

Is There A Strongly Typed RedirectToAction In MVC 2

Oct 2, 2010

I wish to do something like this:

return RedirectToAction<SomeController>(c => Index(someparameter));

How to do this ?

View 2 Replies

MVC :: Do Have Strongly-typed Redirects Yet

Dec 10, 2010

Been using MvcContrib for strongly typed redirects since MVC1. Aren't we there yet with MVC3 or did I miss something (just been scratching the surface)

View 5 Replies

Web Forms :: Assign A Property Of An Object As DataTextField And DataValueField?

Feb 5, 2010

I have a list <Department> say Company.Departments with object Manager and ManagerId, ManagerName as property of Manager. I would like to fill the dropdownlist with managers as below

ddlManager.DataSource = Company.Departments;
ddlManager.DataTextField = "ManagerName";
ddlManager.DataValueField = "ManagerId";

Is there a way to specify the property of an object in DataTextField or I need to copy a Manager list for the DataSource?

View 2 Replies

Forms Data Controls :: Binding Formview To Strongly Typed DataTable In Session Object?

Sep 29, 2010

Okay, here's something that I could easily do the hard way and manually wire up each form element and save it to a datatable in memory, but there has to be a more efficient way to do it.

Here's what I have:

1. A strongly typed datatable and tableadapter in a XSD name Orders

2. A formview control which currently is connected to an ODS connected to the Orders tableadapter, this makes it easy to wire up the databindings for each form field in design view

I would like to:

- bind the the formview to an instance of the strongly typed datatable, and then save the dt to a session object without interacting with the actual database

- load forms on subsequent pages from the dt in session

- ultimately save the dt info to an actual database table on the third page

I've read some solutions where a custom class is created, but to me this seems like almost as much work as wiring up the form field to the table columns manually in code.

View 1 Replies

MVC :: Using A Partial In A Strongly Typed View?

Oct 4, 2010

I have an application that is going to allow a user to create records of type Customer and Seller that have one section in common, but other fields that are unique to their types.

Both of these types will have an address block for their create view.

If I have a strongly typed Customer or Seller view, how can I use the view partial (containing the address block) that I've created? I've tried creating a view model, but I don't know how to have the create page inherit the Customer model and the addressBlock partial inherit the addressBlockForm partial model...

View 7 Replies

MVC :: 2 Strongly Typed Html Helpers Css?

Jul 28, 2010

How can I use css and other attributes such max length with the strongly typed views ?

View 1 Replies

MVC :: @Html.Label Strongly Typed?

Dec 10, 2010

I want strongly typed Label but not working at all. Can you fix the below use of Label to display like @Html.Label("FirstName"). MVC3 Razor.

View 4 Replies

C# - What Exactly Is Strongly Typed View Data In MVC

Feb 2, 2010

What is meant by "strongly typed view data" in Asp.Net MVC ?

View 3 Replies

MVC :: View Strongly Typed With (PagedList Of Xxx)?

Jul 3, 2010

all i have this problem

[code]....

MVC :: View strongly typed with (PagedList of xxx?

View 3 Replies

Strongly Typed API For MVC 2 Async Actions

May 17, 2010

Have anybody tried to create strongly typed API for ASP.NET MVC 2 async actions?

View 1 Replies

Set The DataTextField To A Property Of A Navigation Property?

Jan 30, 2011

i get a list of objects from the Entity Framework data context.

var list = context.EntityA;

the EntityA is the main object (contains the primary key), but has a navigation property called "EntityALanguages", which contains language specific properties.

now i want to bind the list to a dropdownlist and need so set DataValueField and DataTextField properties from the dropdownlist.

how can i set the DataTextField to a property of a navigation property, something like:

this.ddl.DataValueField = "GUID";
this.ddl.DataTextField = "EntityALanguages.ShortDescription";

View 1 Replies

Strongly Typed - How Much Time To Compile A View

Oct 1, 2010

How much time is spent compiling a view in ASP.NET?Of course I don't expect anyone to give me a number, but I think it's interesting to have an idea of how much time this takes because it could influence the way we implement things.For example, if the time is significant , then I might try to put every result that I need to display in the view in a model class instance (created just to hold the values in such a way that I don't even have to test for objects with null value) and then minimize to the maximum (uh?) the amount of C# code in the view thus decreasing the amount of time necessary to compile the view.Question Does this make sense? Give some thoughts on this one.

View 1 Replies

Returning A Single Row In A Strongly Typed DataSet In C#?

Jun 27, 2010

I have a Strongly typed Dataset TableAdapter in C#, how do I get a single row from it?

View 4 Replies

Bulk Update Strongly Typed Dataset?

Mar 7, 2011

is it possible to do a batch update in a strongly typed data set? UpdateBatchSize does not seem to be an option once you create a strongly typed dataset.

View 1 Replies

ADO.NET :: Strongly Typed Dataset Exception Handling?

Sep 28, 2010

I'm currently working on a 3-tier ASP.NET application (UI, BLL & DAL). The DAL uses a strongly typed dataset that I've created with the VS Dataset Wizard. My question is, what is the best way to handle exceptions originating from the BLL and DAL classes. I googled a bit and it seems that the most commonly used practice is to create DALException and BLLException classes and throw your own message. Is this the way forward? how this can be done for an automatically generated DAL? What are the best practices?

View 1 Replies

MVC :: Strongly Typed View With Constrained Generic?

Mar 17, 2010

Can my strongly typed view use a generic with a constraint? The type I want to pass to the view is

RoleGrantedToPerson<T> where T: Aggregate I don't know what T is at design time, only that it is a child of the base class 'Aggregate' I have tried using

System.Web.Mvc.ViewUserControl<RoleGrantedToPerson<Aggregate>>

but at runtime I get an error that the type of the view model supplied does not match the type required.

Is there some syntax/method to accomplish this?

View 8 Replies

C# - ViewDataFactory And Strongly Typed Master Pages

Jan 1, 2010

Im trying to get my strongly typed master page to work in my ASP MVC 2.0 application.have come far with the help of these two posts:Passing data to Master Page in ASP.NET MVCStrongly Typed ASP.Net MVC Master PagesProblem is that im not sure how to get that ViewDataFactory code to work, this is my code:

BaseController.cs
public class BaseController : Controller
{
private IPageRepository _repPage;
public BaseController(IPageRepository repPage)
[code]...

View 3 Replies

C# - Override Strongly Typed @page Masterpagefile?

Aug 17, 2010

I am working with a third party asp.net application that uses master pages and nested master pages. My needs are to dynamically set the master page files for each page(.aspx). The application by default sets the master page file in the strongly typed @Page directive for each page. I don't want to change the strongly typed directive on each page (over 50 pages) because I am lazy and I want to minimize conflicts with future upgrades.

protected override void OnPreInit(EventArgs e)
{
this.MasterPageFile = "~/MasterPages/MyMaster.master";

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved