How can a custom web part read the list item fields in a display/edit form? - sharepoint-2010

I need to create a custom web part and programmatically attach to the display and edit forms of a list. The web part is meant to display some information (coming from another list) about the list item being displayed on the form.
I know how to add the web part to the list programmatically, but I'm having an issue trying to get the web part to read the list item being displayed on from. I know the SPForm object exposes its parent list but I cannot or don't know how to convert the form to an SPForm object. The parent of the web part is the web part manager and the parent of that is the HTML form object. But when I try convert that to an SPForm object it throws an error.
Also, even if I manage to get hold of the SPForm and its parent list, how can I get hold of the list item being displayed?
Please bear in mind that I need to avoid overwriting the default forms as it will significantly increase the development time.
Any help or idea is appreciated.
Regards

Related

Data entry form in sharepoint

I was wondering if anyone knows what a simplest way to create a data entry form in Sharepoint 2010 Foundation would be. Basicly I am looking to create a form that will submit its data to a custom list on the site, I don't want the users to interact with the list directly but use the form to enter data instead.
Also I can't use Designer or InfoPath, not being able to use these is what is causing the problem it seems. Just curious if anyone else has done something like this or could point me in the right direction.
Thanks
Every list is born with forms by default - one for item creation, one for edition and one for displaying. If you use content types, then you get a trio of these for each different type.
You never interact with the list directly, you do it through these forms. If you can't use either Infopath nor Sharepoint Designer, you can still edit them by clicking on the Page tab, then the Edit Page button. From there you can add or remove web parts, and connect them among themselves.
However, the amount of control you have is too limited when compared to editing pages through either of the tools or mentioned, or Visual Studio. For example, there is no straightforward way to add or remove list fields based on content type. Be prepared for ever increasing frustration if you can't use those tools.

SharePoint 2010 and Editform.aspx

In one of my custom application user wants to keep EditForm.aspx open once list item is created and he can keep saving the same record without redirecting user to DisplayForm.aspx page.So what I'm doing after list item creation I'm loading EditForm.aspx again.
Now the problem is when form is opened in Edit mode and if existing field is modified that doesn't gets updated in the list item but if something new added to the field then it gets saved to the list. I believe it's postback issue but not sure how to pass latest form data upon save.
If this was my task, I would create a new application page that replaces the edit page on that list.
(You can use powershell / object model to set the url of the new / edit / display pages)
Ignoring the ribbon, the edit page is actually pretty simple. It shouldn't be too difficult to create a custom one, that has the submittal behavior you are interested in. Indeed, since you are keeping the exact same field names and input types, you may be able to simply inherit the default form in yours, and simply override the post call.
I suppose it might be possible instead for you to write some javascript to hijack the submit post of the default edit page, but this seems messy to me, and I probably wouldn't go that route.
If you don't need to complete this task today, I've been meaning to push to github some code I wrote a few months ago. That code is a custom aspx edit/new/display page that is extremely easy to customize / implement. I could forward you the link tonight when I get out of work.

ECT External Content Type (using Infopath External Item Picker) with List

I would like to create a list with some External Data fields (and other fields) and customize it in Infopath, but it's not working.. InfoPath says:
The following fields in the SharepPoint list are not supported because
of their data type and will not be available in InfoPath Designer:
-field_1 (BusinessData)
-field_2 (BusinessData)
Is it possible to use an External Content Type (WCF Service) with a list in Infopath?
I mean, use an External Item Picker in a Infopath form that connects to a list. Or is it only possible with a Form Library?
Any ideas on how to solve this or a suggestion to another approach?
Thanks in advance.
It is possible to create the scenario you're referring to... if I understand you correctly, you want to use the External Item Picker to create a pick list within an external list against another list.
You would have to associate the two external lists (ECTs) within your BCS model. This association must be a foreign key based association. That done, SharePoint will automatically create an External Item Picker in the default list form.
I'm currently doing the same thing and it works for me in Sharepoint. However, when I modify the form in Infopath, I start to get errors whenever I select an item in the External Item Picker. As long as I don't use InfoPath to modify the form, it works fine in SharePoint.
I hope this answers your question.
Cheers!

Bind a SharePoint list to a Silverlight Dataform

I am using the SharePoint client-object model to read data from a list and I was finally able to correctly get the data but now I am having difficulty actually displaying that data. I would like to use a dataform control to both add and edit the SharePoint list but am thus far unable to get it to actually display the items in the list. If anyone knows how to connect a Dataform control to a sharepoint list I would be very thankful.
You have to bind your list to the control. Have a look at the following page: http://dotnetslackers.com/articles/silverlight/The-DataForm-Control-in-Silverlight-3-Revisited.aspx section "Data binding" explains the steps you need to make (setting the DataContext property).

How to implement different value for Multiple instances of same webpart in subsites?

I create a webpart, for which values are provided dynamically through the toolpart. I get the proper output. But the problem is when i add a new instance of the same webpart in a subsite, It takes the value from the other tool part,
In simple words, The value in the toolpart remain same for all the instances of the same webpart. I need to handle different value for each instance of the webpart.
Can any of you have a better solution for this problem.