Dynamically populate an InfoPath DropownList with managed code - c#

I have an InfoPath form with custom C# code, and a Sharepoint list. I have a dropdownlist in the InfoPath form that I want to populate with a certain field from the Sharepoint list (I want the InfoPath dropdownlist to contain this field's value from every item in the Sharepoint list. I can successfully get the list of values I need from Sharepoint in my managed code, but I do not see how I can get these values into the dropdownlist (either bind to the list, or add each item in the list one by one). I thought I could modify the XML of the dropdownlist to insert my items, but the XML only contains the first item in the dropdownlist:
<my:RelatedRiskID xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-07-20T18:12:59">Option 1</my:RelatedRiskID>
I feel like this should be possible, but I can't find any resources on how to do it. Thanks in advance for the help.

If you plan to populate your dropdown list with a SharePoint list then you need to
create a data connection to the said SharePoint list
in the dropdown list Data tab, get the data externally and select the said data connection

Related

Multiple row input in asp.net for editing database table

From time to time, I need to create an input control which allows multiple rows of input, the type of input and number of columns could be different in each case but typically it would be represent a database table being edited, so it should also be possible to store an id value within each row. It should also be possible for the user to add new rows to the input if they have more data to input.
I have tried a couple of approaches to this but they are all very long winded for what seems like such an obvious and common scenario. I'm thinking that there must be a simple way to do this that I have missed.
The way that I usually solve this is by using a list view, enter all of the input controls required within the item template and use a html table for formatting, with each item being a row of the table. If there is existing data to be edited, I would load the data from the database, add a blank object to the results and bind it to the list view. If there is no existing data, I would create a collection with a blank record in it and bind it to the list view. I add a button for adding a new row. When clicked, this button retrieves all of the existing data from the list view by iterating all of the listview items and populating the data into a collection, which I would then add a blank object to and rebind the listview with the results. When saving, I would retrieve the results by iterating the listview items again and using a hidden field within each row to store the record id. This would determine whether a new record was added or an existing record was edited.
This approach works for me but I'm sure there must be simpler ways to achieve this. Looking forward to seeing how other people solve this.
For web forms, use a GridView. You can set its properties to allow editing, deleting, new rows, sorting, and paging.
Check out the MSDN example here that shows how to use it. If you bind a datasource to it, it will figure out the columns and adjust dynamically then, or you can predefine the columns you want for more customability.
You are talking about bulk insert/update. You could use XML insertion/updation for this purpose. Get all the data to a DataSet ds variable. Then use ds.GetXml() method to convert the dataset to XML string. Pass this to an XML parameter into SQL server which has the datatype 'XML'
INSERT INTO YOURTABLE
SELECT
V.VOI.value('(.)[1]', 'int')
FROM
#Input.nodes('/DATASETNAME/DATATABLENAME/') V(VOI)
Use this link to learn more
You need dynamic table with Add, View,Edit and delete operations on each data.
I would suggest using DataTable Jquery component. there are tons of examples on Data operations, and you can plug this with any Server technology including ASP.net
http://editor.datatables.net/

Get entire dropdown list items into an array in InfoPath

I have an InfoPath XSN form template with a dropdown list. This is bound at design time to a data source and populated with a list of names when the form is loaded.
I would like to get hold of all of the names in this dropdown list into an array for processing elsewhere on that form. I have tried to get hold of a reference to the dropdown list as below (and similar variations);
XPathNavigator myNav = this.MainDataSource.CreateNavigator();
object dd = myNav.Select("/dfs:myFields/dfs:queryFields/q:Site/#STitle", this.NamespaceManager).Current;
But I'm only getting the current value and not able to get hold of the entire list. Any one able to help please?
You can attach to the datasource you bound the listbox to (a secondary data source) the same way you are attaching to your primary.
XPathNavigator myNav = this.DataSources["datasourcename"].CreateNavigator();
Then just use the navigator to work with the fields/nodes as normal XML, so you can put them in array or just use the collection of nodes or whatever.
The MS documenation has some simple examples of connecting to a secondary data source and selecting nodes (among other things).
http://msdn.microsoft.com/en-us/library/office/bb509311(v=office.12).aspx

Get a Sharepoint ListItem Based on Date?

I have a Sharepoint List which is sorted by a Report Date.
Within a Visual Webpart I have created an html report which references the ListItems. One of the options on this Webpart is to change the date. If the user changes the date I need to be able to retrieve the ListItem corresponding to that Date from the List. Using c#, how can I get a handle on the Item in this way?
Thanks
I think you have your answer here
http://snahta.blogspot.com/2009/04/getting-list-item-updated-in-past-few.html
Few more good tips # http://snahta.blogspot.com/2009/07/spquery-few-important-things.html

C# Windows Application Form and Data base

I am loading elements (a row) from a database in a list. Which technique should I use to update the list when a new entry is added in that table ( SQL database) so that the lists updates and if I have selected an element from the list it won`t get deselected (like Outlook when new mails are received and you have a mail selected ).
If your dealing with simple database transactions, I would recommend a foray into the BindingSource Component. The BindingSource component can take care of creating, reading, updating and deleting things so you don't have to.
I assume your rows have a unique identifier. You can store this Id before you add the new row, and after it's added you can search the list with the stored Id to re-select that row.
(Actually it would be wiser to store the row handle and re-selecting it directly with the handle. But it wouldn't work if your grid creates new row objects to display the updated list. Since I don't know how you bind your data, I cannot say this would work for sure.)

Set selected value in a SharePoint Dropdown list

We are using SharePoint 2010 Foundation.
We have an item in a list that is a dropdown with values from another list.
When we access the list as a SharePoint list it works fine, we can select a value, save the list, the next time we access the list the correct value is selected.
We have programmed a form that will updated the list. When we pull up the form, select a value and save it, we can see by accessing the list directly that the value has been saved.
However, when we pull up the form again it is the first item in the list that is selected. Have tried storing the selected value is a temp variable before binding the list but have not been able to get it to work. Anyone know how to fix this?
We found a solution.
The trick was to get the number that is the first part of the ToString of the SPListItem, before binding the list.
Then use that number to set the selected value after the list is bound
Parameters:
SPListItem currentItem, string fieldName
Code:
string selectedValue = currentItem[fieldName].ToString().Substring(0,1);
//... Bind list
ddlLookup.SelectedValue = selectedValue;

Categories

Resources