MVC :: Understanding Binding A Field Value?
Jul 26, 2010I am trying to make a master - detail form with mvc.
I use ajax tab control for this.
I use MvcContrib.UI.Grid.
[URL]
I am trying to make a master - detail form with mvc.
I use ajax tab control for this.
I use MvcContrib.UI.Grid.
[URL]
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.
The short version of this question is "is there a way to gracefully accommodate automatic field binding & database insertion for an object that has a many-to-many field that has been set up in a partial class?" Apologies if it's been asked before.
Example Suppose I have a typical MVC setup with the tables:
Posts {PostID, ...}
Categories {CategoryID, ...}
PostCategories {PostID, CategoryID, ...}
As far as I know, there's no way to do many-to-many relationships in Linq-to-SQL right now so I have to shoehorn it in by adding a partial Post class to the project to add that functionality. Something like:
public partial class Post{ public IEnumerable<Category> Categories{ get { ... } set { ... } }}
So I can now create a "Create" view that automatically populates a "Categories" UI item. It even handles like any other field- fun!
So here's my problem:
How does all of this get exposed to views like "Create" and "Index" and still get to use automatic object model binding? The goal is to a) have the view and automatic model binder treat this as if it were native functionality of the object and b) have the Post object gracefully handle creating PostCategory table entries on submission into the database.
I have a DetailsViews that I have added a dropdownlist. When I am in the EditBindings area of the EditItemTemplate, click on SelectedValue the "Field Binding" radio button under "Binding for SelectedValue" is grayed out and not available. I have a tutorial that is very clear on how to add a dropdownlist to a GridView or DetailsView and I feel everything is setup correctly. The dropdown box is working with the available choices but is obviously not binding the selected data.
View 8 RepliesI have got a list of person with address object attached to it. When assigning the values to the report, how do I binding
address.address1.value
address.address2.value etc
to the textbox of local report.
i have two button in form i want to bind required field validator to only one button, bcaz it invoke in both button.
View 3 RepliesI want to bind a datarow array to datagrid, if i do so i am getting an exception saying that item was not found on selected datasource.
datatab = CType(Cache("AlldataAppli"), DataTable)
Dim rws() As DataRow
rws = datatab.Select("uid=" & UID.Text)
dg.DataSource = rws
dg.DataBind()
While binding the data i am getting the following exception.
An exception of type 'System.Web.HttpException' occurred in System.Web.dll but was not handled in user code
Additional information: A field or property with the name 'CAND_NAME' was not found on the selected data source.
This datarow array contains cand_name, i am able to retrieve it through the following line of code.
rws(0).Item("CAND_NAME")
I've got a gridview with a hidden field, i'm trying to set a value as follows:
value='<%# DataBinder.Eval(Container.DataItem, "Name")%>'
which works in most cases except when the name has an apostrophe like O'Neil. I need to escape the ' if possible.
so i tried: value='<%# DataBinder.Eval(Container.DataItem, "Name").ToString().Replace("'", " /' ")%>' and
value='<%# DataBinder.Eval(Container.DataItem, "Name").ToString().Replace("'", " //' ")%>'
which doesn't work because of the final apostrophe in the notation i.e. %>' It truncates after the word e.g O'Neil Someone becomes O' which is incorrect.
This works like a charm: value='<%# DataBinder.Eval(Container.DataItem, "Name").ToString().Replace("'", "'")%>' which isn't good practice as I don't want to hardcode '
I need to bind a List control based on the Gridview Row's datakeyName value while the Gridview control is being loaded into the page. I tried the following but it does not work.The BulletedList control is nested inside a Gridview Control and they both bound to an ObjectDataSource control. In my code, I passed teh UserID into the UserID parameter and call the Select() method but still does not work. Basically, I want to list of a user's hobbies, therefore the hobbies control are driven by the userID. tell me how can I get it to work?
protected void UserGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
int UserID;
[code]...
I know that you can use exclamation sign to bind array of simple types (like string) to GridView like this
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField HeaderText="Array Field" DataField="!" />
</Columns>
</asp:GridView>
But this doesn't seem to be the case with DataNavigateUrlFields
<asp:HyperLinkField DataNavigateUrlFields="!" DataNavigateUrlFormatString="RoleInformation.aspx?role={0}" Text="Manage users" />
and I get following error:A field or property with the name '!' was not found on the selected data source.
For example, i am using forms authentication... and i notice there is a system.web and then it closed /system.web and then below configuration there are additional location tags.here is an example, if you ntoice there is an authentication mode=forms with authorization i presume this is the ROOT....... It is also self contained within a system.web .... Below this there are more location= with system.web tags....I have never really understand what i am actually doing.. I have tried checkign the MSDN documentation but still i don't fully understand up....
If you notice with my example.... everything is stored in 1 web.config... i thought the standard waas create a standard web.config and then create another web.config in the directory where i wish to protect it..???
<configuration>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />[code]....
understand what is going on in the code line below:
Table t = (Table)Page.FindControl("Panel1").FindControl("tbl");
I understand Page.FindControl("Panel1").FindControl("tbl");
Why is there a (Table) before the Page.FindControl?
string sqlstring =
"SELECT DISTINCT STAFF_ID, SCHOOL_CODE FROM MODULE_TIMETABLE_STAFF WHERE STAFF_ID != '" +userId +
"' AND STAFF_ID LIKE '%" + Searcht +
"%' ORDER BY STAFF_ID ASC";
can anyone explain this statement for me? especiallythese signs !=,+ +
i am new to MVC and i want to learn it. Please advise me some good material for understanding Asp.Net MVC framework.
View 1 RepliesI am working on a project for my company, and while tracing previously written code I came upon this:
<value>A payment authorization for {0:C} has been received.</value>
What does {0:C} mean? I have been trying to find out and am having no luck.
Special symbols are a real pain to learn about because you can't Google for them (try doing a Google search for "<%#" and you's get nothing).
I've been a programmer for many years, and I'm trying to get my head around ASP.net, and especially the "special symbols"; what they mean, where to find out more information about them. Because they're impossible to search for, it'd be wonderful if there were special resources in place to help newbies learn about these.
Specifically, I'm looking for detailed instructions on the porpose for, and use, of the following constructs:
<%@ %>
<%$ %>
<%# %>
<%= %>
What is expected in each, what is allowable in each, and what "gotchas" would a newbie have to be careful for when employing each.
For example, I want to do some coding in a <%# %> block, like:
Text="<%# if (Eval("InUse")) {Eval("ProductName")} else {"Not In Use"} %>"
-- would this be allowable, and if not, what are reasonable alternatives?
your posts and answers are very informative and helpful in my own devolopment and understanding the nature of the beast. Im running vs2010 on a 64bit windows 7 devolopment machine. For days I have been trying to get a Microsoft Reportview to render in a popup. ( i have done this in vs2008 ). I have tried applying the same code from vs2008 to Vs2010, but am comming up with page erros. When loading the default.aspx ( testpage ) I get 'Done but with errors'. If I click on button 1 which shows the popup, I get the report viewer, but it just sits there 'loading'. From advice givenm on this forum, I have used the IE view source code to try and loacate the problem... but to be honest, I dont understand why the page complies ok, but i get errors when it is run, or indeed how to rectify the problem. I have highlighted the two errors.Ie view source code:
[Code]....
[Code]....
[Code]....
I am new to ASP.NET MVC 2 and I am having a very hard time figuring out how to do even the most simple things. I have a couple of books on ASP.NET MVC as reference but I cannot find any answer to my question. Here is what I basicalyl have and need:
I am trying to create a page that shows me a table that contains some Product Statistics with columns such as Date, ProductCount, PriceCount. On the same page I want to add some filters such as "Product category" (dropdown) and a date from and date to (jquery ui datepicker). When a user clicks on "Filter" it should reload the page and in the Product Statistics it should show the statistics filtered by "Product Category" and the date range. At the same time I want to make sure that the selected Product Category from the dropdown list does not get lost, the same for the date pickers.
I have a GlobalReportController with two actions: "Index" and "Filter". I have also a GlobalReportIndexViewModel and a ReportFilter. In the "Index" action, I retrieve the complete list of statistics and product categories and fill up the ProductStatisticsIndexViewModel.
I am having a whole lot of problems trying to grasp how the ASP.NET MVC paradigm works exactly.
I'm trying to build up some regular expressions to validate some textbox controls. I have done some research and testing but cannot get this one working. Examples of what i am trying to create regular expressions for are as follows:
Range 0-45, 0 decimal places
Range 0-20, 2 decimal places
Range 16-65, 0 decimal places
Range 0-99, 2 decimal places
Range 0-1500000, 0 decimal places
Range 0-200, 1 decimal place
For 1 and 5 respectively, I have used
([0-9]|[0-9]d|45)$
([0-9]|[0-9]d|1500000)$
The first one I am having problems for is an age range of 16-65 (inclusive), where I want no decimal places. After a post on here (Regular expression to allow numbers between -90.0 and +90.0) I thought I could use the logic and get it sussed, but can't! The expression I got to was:
(d|([1-6][6-4]))|65
I am building a medium to large application with ASP.NET MVC 1.0 (we'll upgrade to the latest after we meet some schedule commitments). The application contains a number of workflows, with a separate controller for each workflow, and the home controller owning the main page of the application. So, I end up with the home page, on which the user makes selections and then clicks one of a number of action buttons to proceed down a given workflow. For a given workflow, I seem to have the following flow between controllers:
homeController (home view) --> action-button --> workflowController --> homeController (completion view)
I figure the action-button does a post to the home controller, which the selections the user made are saved to session state in the appropriate model. The workflowController will handle things as the user moves through one or more views specific to the workflow, but then things end on a common completion page.My question(s):1 - Is this a reasonable way to break up responsibilities amoung multiple controllers?2 - How do I actual accomplish the hand-off to the workflow specific controller? I'd really like to avoid a redirect and the attendent round trip to the browser since controller structure is really an internal implementation issue and shouldn't impose a performance penalty on the user.3 - Is it possible to pass a model from the originating controller to the destination controller, or do I have to exclusively depend on persistent state to pass things to the "next" controller?
If I create a new project, start this project and look at the source code, I see that there are some additions to the original code. The first this, what is "ViewState" and what does the hash mean? Why is the input control hidden?Here an example:
[code]....
I have an ajax form that has a simple click event. Inside the click event, at the end of the method, I have a Response.Redirect back to the same page. For the purpose of this thread, I will leave out the reasoning of this (it is just something that I had to do). Once the ajax call is complete and the redirect takes place, all of my default control viewstates get wiped out. The thing that doesn't make sense, is that if I define my own ViewState right before the Response.Redirect, these ViewStates also get wipedout. So, my question is, do ViewStates only hold their values after one postback/refresh? And, is there a way to use ViewState with the method described above? I am being forced to use the querystring to pass parameters.
View 2 RepliesI've searched for about a day and a half and have not been able to find an explanation that I can understand, so please forgive me if this is something you have seen/answered before.
I have a web site that uses the App_Code folder. There are several CS files and classes in that folder. All of this works fine up to this point. However, I wrote an extension method with its own class and file. This fails with the following ambigous reference error (the app is in C#):
Compiler Error Message: CS0121: The call is ambiguous between the following methods or properties: 'GSGeneral.ExtensionMethods.IsNumeric(string)' and ''GSGeneral.ExtensionMethods.IsNumeric(string)'
If I change the extension to a plain static class, there are no problems with it. Based on that, it seems like this is related to it being an extension method.Now I know a work around is to move the file out of the App_Code folder - I've tried it and it works. My question is why does this have issues when all of the other items in the App_Code folder do not.
I have a DetailsView with some templates. I would like to bind a textbox in one of the templates to a field of a datasource which is not the datesource of the DetailsView. What is the syntax of the Bind() or Eval() code expression to do this, assuming it's possible?
Also where can I find some material on syntax of these "code expressions" and what can be in them?
I realize I'm missing something pretty basic here...
[Code]....
[Code]....
[Code]....