Reputation: 863
I have a simple list and I created a New Item Form using Sharepoint:FormField to bound list data to fields, but I would also like to know if there is a way to do the form using asp.net controls.
My problem is that I have 2 cascading dropdownlistboxes implemented as asp.net controls Project Name - Project Module that implement my business logic and i would like to bind them to list data.
Thank you !
A detailed description of my test project: I want to build a list to allow team members to report time spent in projects, working on project modules.
So I created a list that contains a couple of projects and a couple of project modules. A single text column with project name, and a multiple line text column that contains all the project work items .
I created another list (Time Management) that should contain the actual time report data: A user column, a date column, a number of hours column, a project name, a project module.
Afterwards I wanted to change the New Form on the Time Management list to include a 2 cascading drop down boxes that will allow the user to select the project name and afterwards the Project Work Item, so I created a new Visual Web Part and added only 2 drop down boxes with some custom logic to link to the Project List and retrieve data:
My .ascx code:
Project Name:<asp:DropDownList ID="ProjectName" runat="server"
AutoPostBack="true" onselectedindexchanged="ProjectName_SelectedIndexChanged" />
Project Module:<asp:DropDownList ID="ProjectModule" runat="server" />
<SharePoint:SaveButton ID="btnSave" runat="server" ControlMode="New" />
<SharePoint:GoBackButton ID="btnBack" runat="server" />
The problem is that the 2 dropdownlists are not binded to New Item Object; instead all the examples that I have use a SharePoint:FormField control that handles the binding automatically, and I was wondering if I can do the binding myself directly on the asp controls.
I found an interesting link here about Data Binding on asp controls: Is there a good reference SharePoint's databinding syntax? but it's not beginner friendly.
Upvotes: 1
Views: 3080
Reputation: 203837
SharePoint is built on top of ASP.NET, so pretty much anything that you can do in ASP you can do in SharePoint. Personally I use a good mix of both in most of the projects that I work on (or at least the ones that I think are the better ones). If you're coming from an ASP background and are more familiar with that, you can essentially make an ASP site and just stick in a few SharePoint-y things here and there rather effectively.
As for your particular issue. I personally don't like using the actual data binding methods. I prefer to just add items to the control myself. This means that in the code behind in the page_load method I would query the list (or wherever you have the data) loop through it and add the items to the drop down. If you want to use ASP.NET style databinding on the controls, it won't be any different.
Upvotes: 1
Reputation: 744
You can implement cascading drop downs relatively easily by using a custom infopath list form. See details here
See this example to learn on how to use cascading drop downs.
EDIT:
I want to know if I can use asp controls or not, and if I can how to bound them
Yes. New item form is basically an aspx page and you can use asp.net controls or third party controls like telerik, infragistics etc.. You can bind the data and use event handlers by inline code or by using code behind file. Writing code in SP designer will not be a pleasant experience though.
Upvotes: 0