Hello,
I have a FormView to Insert records to the DB. It works fine. Here is the pattern of it :
ItemType="VincitoreCRMApplication.Models.Inquiry" DefaultMode="Insert"
InsertItemPosition="FirstItem" InsertMethod="InsertItem"
OnItemCommand="ItemCommand" RenderOuterTable="false">
DataField="ProjectName"
DataTypeName="VincitoreCRMApplication.Models.Project"
DataTextField="ProjectName"
DataValueField="ProjectId"
UIHint="ForeignKey" runat="server" />
DataField="ChannelId"
DataTypeName="VincitoreCRMApplication.Models.Channel"
DataTextField="ChannelFullName"
DataValueField="ChannelId"
UIHint="ForeignKey" runat="server" />
and lot more fields. All fields come in Vertical order - 1 after another.
I want the same fields but in different format/view. Like a panel with a title on it for all Name & address details, another for other dates details, other firm details, etc. I also wish to have a link for each panel dept on top, thru which user can just navigate to that part of the page.
Can you suggest me how can I achieve this ? I prefer to use DynamicControl as it becomes easy to handle the saving & retrieval part of the DB. Finally on the "Submit" button click, I can add the record using Model Binding :
public void InsertItem()
{
Inquiry item = null;
item = new Inquiry();
//item.Id = 1;
TryUpdateModel(item);
if (ModelState.IsValid)
{
//Inquiry newInq = item;
// Save changes
_db.Inquiries.Add(item);
//System.Diagnostics.Debug.WriteLine("### ID OF Newly Created CHANNEL = " + newInq.Id); // Save changes
_db.SaveChanges();
System.Diagnostics.Debug.WriteLine("### EF ID OF Newly Created INQuiry = " + item.Id);
Response.Redirect("Default");
}
}
Can I place the same Dynamiccontrol's in different Panels or div and make the LnF different ? And on Submit button call the InsertItem code ? If I use DynamicControl, then I guess I will have to mention the Model Type of it. How and where can I add that ?
Can you please help me solve these queries and help me create different View using Model Binding.
Yet, all suggestions are welcome.
Kindly suggest to your best based on my needs.
Thanks
Vincent Maverick DuranoPosted May 10, 2015, 11:17 AM
If you are using ASP.NET 4.5 then there's no need for you to use those messy requiredfield validators. Once you model is decorated with data annotation attributes then the validation message will display in the validation summary. See:
http://www.asp.net/web-forms/overview/getting-started/hands-on-labs/whats-new-in-web-forms-in-aspnet-45
TerryPosted May 9, 2015, 10:56 AM
I am already using Entity Framework. And I found that if I manually create a Model obj & assign all fields value, while saving the record to DB (db.Savechanges() method) that calls
IEnumerable
Can I put
on top where all the message of Validate() will come up ??
In my Model, I already have code as :
Will this help me in my ValidateSummary or I will have to add in my aspx like :
What do you think, how should I go through ? And reg Entity Framework other than the above, am I missing anything that I can and should implement in my case ??
Kindly suggest me.
Thanks a lot.
Vincent Maverick DuranoPosted May 9, 2015, 7:01 AM
You could actual use Divs and Panels to layout form elements in your page:
The downside for that is that you would not be able to utilize or use ModelBindings since ModelBindings only applies to Data Controls such as GridView,FormView,DropDownList, ListView, etc.. Adding to that you will not be able to use DynamicControl too since it only applicable for Templated controls such as GridView, FormView, ListView, etc..
This means that you when opt using Panels/Divs and have some TextBox in the form then you would need to manually bind each TextBox by hand. One example is using ADO.NET or Entity Framework to fill your TextBox with data.