So I have the code as such:
private void newAddFormForMembers(SPList list, SPWeb web)
{
list = web.Lists["MemberRecords"];
string url = string.Format("_layouts/createform.apsx", web.ServerRelativeUrl, list.RootFolder.Url);
var form = web.GetFile(url);
if (form != null)
{
list.DefaultNewFormUrl = url;
list.Update();
}
}
I have used SharePoint 2010 designer to go and grab the existing html for the creatform form when adding items to a particular list. I added in two new fields, first and last name. The list contains a member name, I removed this field from the create form because:
When I hit submit to add the item to the list, first and last name need to format them selves into "lastname, first name". Now I could submit the form back to my self - How do I do that? - and then do my string manipulation How do i get the values form a field? - and then push the information to the list How do I do that? but then I have anew issue
Edit will look the exact same as add, first and last name fields, how would I take the information from the list and populate the new edit form, particularly first and last name fields, keeping in mind that in the list they are in the format of "lastname, firstname"?
This is all being done programatically
Instead of change html newForm for the list try to write an Event Receiver
Instead of delete field from the newForm try to hide columns (You can do that programmatically or using external tool such as Sharepoint Manager
Adding fields to the new/edit form and grab value on postback event I think is not simple/possible (via javascript you can access onPreSave where you can manipulate item values before postback, here you can write some jscript for save values into field but on edit is hard to split values).
You can: create two column on your list FirstName and LastName, plus a third field FullName (hidden for new/edit form) and with an EH on Added/Updated you can write FullName = LastName + ", " + FirstName or without EH you can create a calculated Field.
Related
This concerns an approval field on a form. In the database, it's a bool field, an int field containing a FK to approvers, and a date-time field that, together, indicate whether something was approved and if so, who approved it and when. On the form, this has to translate into something like "Approved by John Smith on 01/02/03 04:05."
I handle this with a navigation bar. When the binding source position changes, the event is trapped and the code formats the calculated fields, like this (what the code does it not that important).
private void ctlNavBar1_displayCurrent(object sender, EventArgs e)
{
var drv = talsBindingSource.Current as DataRowView;
if (drv != null)
{
ctlBoundCheckButton1.lblText = $"Submitted {drv.Row.Field<DateTime>("SubmitDate").ToString("MM/dd/yy hh:mm tt")}";
ctlBoundCheckButton1.setControls(true);
if (drv.Row.Field<bool>("Approved"))
{
var sup = talsSupervisorsBindingSource.Current as DataRowView;
ctlBoundCheckButton2.lblText = $"Approved by {sup.Row.Field<string>("FullName")} on {drv.Row.Field<DateTime>("ApproveDate").ToString("MM/dd/yy")}";
ctlBoundCheckButton2.setControls(true);
}
}
else
{
using (DialogCenteringService centeringService = new DialogCenteringService(this))
{
MessageBox.Show("No TALs to Approve", "Confirm", MessageBoxButtons.OK);
}
Close();
}
}
The problem is that
public TALsApprove()
{
InitializeComponent();
talsTableAdapter.FillForApproval(timeTrackDataSet.TALs, User.ID);
usersTableAdapter.FillBySupervisor(timeTrackDataSet.Users, User.ID);
timeSlipsTableAdapter.FillBySupervisor(timeTrackDataSet.TimeSlips, User.ID);
ctlNavBar1.displayCurrent += ctlNavBar1_displayCurrent;
ctlNavBar1.bindingSource = talsBindingSource;
// this assignment doesn't fire Position Changed (or anything else, as far as I can tell)
}
the binding source event PositionChanged does not fire when the binding source is first assigned. I've worked around that by using the form Shown event, like this.
private void TALsApprove_Shown(object sender, EventArgs e)
{
ctlNavBar1_displayCurrent(null, new EventArgs());
}
So my questions are:
1.- Does calling event handlers directly like this mess with any of .NET's internals? (e.g. memory leaks, stack problems, etc.)
2.- Is there a less kludgy way of handling the calculation of fields when the binding source is first initialized, as well as when the contents of the current record change? I experimented with the binding source events CurrentChanged and CurrentItemChanged, but they seem to over-fire, firing even when no actual field value had changed.
There are a couple of ways I might think to tidy this up:
1 ) Use a calculated column
Assumptions:
You have a strongly typed DataSet with two tables like Applications and Users
You have the following columns in Applications: Approved(bool), ApproveDate(datetime), ApprovedByUserId(int)
You have a single datarelation between Applications and Users that maps Applications.ApprovedByUserId (many) to User.UserId (one), and UserId is also an int
Process:
In your dataset click in your Applications table, and add a string column
Set its Expression property to something like: IIF([Approved] = False,'Not approved','Approved by' + Parent.Username + ' on ' + [ApproveDate])
You have some process alreadythat fills good data into the table:
When you run the app it becomes the datatable's problem to build the narrative:
Let's edit another detail in at runtime:
When you finish the edit and move off the row it will be committed to the table and the narrative updates automatically
You can read more about what syntax you can use in DataColumn.Expression
If you don't have a bool approved you could add one or use some other test like IIF(ApprovedByUserId IS NULL,'Not Appproved,'App...'). If yo uhave multiple datarelations coming off Applications you specify the name of the relation after Parent like Parent(App_User).UserName` assuming the datarelation is called App_User
Bind different things on the UI
Noone ever said you only had to bind Text. If you had a "Approved" bool column in your dataset, you could have several labels in a row:
--label1----- --label2------ --label3-- --label4--
"Approved by" BindParentName " on " BindDate
You can bind every one of their Visible properties to the Approved bool so the labels disappear if the user navs to an unapproved row.
The easiest way to get the parent user name into the Applications data table (because all these labels are bound to a indingsource that sits on the Applications table, right?) is to use an Expression on a new column like above, but simpler (just Parent.UserName or Parent(App_User).UserName`) to import the user name into the Applications datatable.
There are other ways, involving multiple binding sources that bind to datarelations.. We can even jiggle a combo box into doing it - the combo has a DataSource of the users table, but a DataMember of "ApprovedByUserId" from the applications table; it will perform 2 way lookup of the ApprovedByUserId <--> UserId equivalence
I am working in an CMS called RiSE, and have many constraints. I am also thinking in PHP while trying to output C#.
I have a contact form that is being dynamically generated by being put together by "iParts". Each iPart includes an ASCX file into the wizardry of templates and junk.
As an example, I could have 2 iParts that each add a text box. How do I generate a list of these 2 text boxes that I can recall after post as to get the values?
What I am doing now, and almost works....
I have what I think is called a controller, and it (I think) defins a property like so;
namespace EmailForm
{
[DataContract(Name = "EmailForm")]
public class EmailForm : iPartCommonBase
{
public static Dictionary<String, String> inputs = new Dictionary<String, String>();
}
}
Now in my (I think) Controller, I add to the Dictionary inputs like so;
EmailForm.inputs[randId + "_" + inputEmailLabel.ToString()] = input.UniqueID;
What I end up with is a key value pair list that contains a label prefixed with some random string (to prevent crashes/overwrites) and the id.
When the form is submitted I loop through the dictionary and use the ID string to access the posted value. Pretty straight forward, BUT, if I reload the page say 3 times before filling the form and hitting submit, I end up with 6 entries into my Dictionary, all but the last 2 reference non-existant ID's.
What should I do differently? (and unfortunately, use LAMP is not an option)
In the end I have found a simple solution, I think it's a hack, but so is ASP
if (Request.Form.AllKeys.Contains(post.Value))
{
emailBody.Add(post.Key.Substring(8) + ": " + Request.Form[post.Value]);
}
The Dictionary still contains "rogue" entries, but I filter them out by existing post data.
I have around 20 cities in my database. I need to develop a page where I can allocation some value to each city. I can update the allocation in the page.
My Data base looks like below
City table - > City(CityId, Name)
I have a table to store the allocation for cities
Table - > CityAllocation(CityId, Allocation)
I have to display a text box near all the city names.
CityAllocationViewModel.cs
public class CityAllocationViewModel
{
public List<City> Cities{get;set;}
public List<CityAllocation> CityAllocations{get;set;}
}
CityAllocation.cshtml
Step 1: To display all the cities I will loop through Cities list and display it.
Step 2: Need to display text boxes near each of the city -> which will load existing values from CityAllocations if anything is there. Otherwise just need to display empty
But for the first time CityAllocations list will be null. Can someone explain me how to construct text box with proper binding name so that when I save it, the values gets properly binded to action method parameter. I am using MVC 4.
My Action method looks like below
CityController.cs
public ActionResult SaveCityAllocation(CityAllocationViewModel cityAllocationViewModel)
{
}
I will suggest use EditorTemplateFor . Create a partial View for CityAllocation and call in main view CityAllocationViewModel with as #html.EditorFor(m=>m.CityAllocations)
I have added a new custom field in CMS_UserSettings table. The form control type is Multiple Choice. The data source for the control is set to a SQL Query. I would like to be able to populate the items in the control based on the selected user (Administration > Users). NOT the current user. Anyone know the syntax for this? Is it possible?
Here's my sample which pulls in the current users attribute. I need this to be the selected user.
SELECT ItemID, dealerNumber + ' - ' + dealerTitle
FROM cPort_DealerLocation
WHERE culliganGroupID = {%CurrentUser.culliganGroupID#%}
ORDER BY ItemID
You can access currently edited object through EditedObject macro - {%EditedObject.FieldName%}.
Edit:
It seems that a custom macro method is needed to do this for documents. I was able to do this by following code:
1) Create custom macro method (for how to do it see the documentation
MacroMethod method = new MacroMethod("MyEditedDoc", parameters => CMSContext.EditedDocument)
{
Type = typeof(TreeNode),
Comment = "Returns currently edited document.",
MinimumParameters = 0
};
MacroMethods.RegisterMethod(method);
2) Then in field editor of a document type you can use {%MyEditedDoc().DocumentName#%} and it gets resolved on the Form tab.
I have 2 webforms with 1 ListBox Control on each of them.
How do I access the Listbox that's located on webformA from webformB?
For example I wish to declare something like this string name = ListBoxWebformA.SelectedValue.ToString(); on WebFormB, so that I can work with that value in the code of WebFormB.
The ListBox on WebFormA lists several names.
When I select a name from the listbox and press the OK button I call Response.Redirect("~/WebFormB.aspx");
So from WebFormB I wish to access this "name" by putting the selected value into a string.
Based on your edit, the easiest (possibly best) way to go about doing this will not be to try to maintain a stateful instance of webformA during the request to webformB. Once the user is redirected, assume that webformA is gone.
Instead, when you're about to perform the Response.Redirect() to webformB, include in some way the value from webformA that you wish to pass along. The easiest way to do this will be on the query string. Something like:
Response.Redirect(string.Format("~/WebFormB.aspx?name={0}", HttpUtility.UrlEncode(ListBoxWebformA.SelectedValue.ToString())));
Then, in webformB you can access the value:
string name = Request.QueryString["name"];
Note that you'll want to do some error checking, etc. Make sure the value is actually selected before appending it to the redirect URL on webformA, make sure Request.QueryString["name"] contains a value before using it in webformB, etc.
But the idea in general is to pass that value along, by query string or POST value or Session value or some other more stateful means, when redirecting from one form to the other.
I guess you have to resort to either passing the value from A to B in the query string or storing the value in Session and reading afterwards.
So would be a
Response.Redirect(string.Format("~/WebFormB.aspx?YourVariable={0}",HttpUtility.UrlEncode(ListBoxWebformA.SelectedValue));
and you can read it in Form B like
Request.QueryString["YourVariable"]
If the values are not sensitive this approach above would be the best.
If they are... To store in Session:
Session["YourVariable"] = ListBoxWebformA.SelectedValue
And to read...
if (Session["YourVariable"] != null) {
var listAValue = Session["YourVariable"].ToString()
}