I just created a custom new form web part in C#. It works great and adds a new item to the list with the 'Save' button.
Now, I am trying to reuse the same code to create the custom edit form. But I am not sure how the edit form will now already have all the data populated in the fields. Is there a way to bind the textboxes, etc to the list fields?
Also, now the save button should not add a new item to the list, rather it should edit the current item. What changes should be done in the save button onClick function?
The current ascx page is like -
<table cellpadding="10">
<tr>
<td>Created By:</td>
<td><SharePoint:PeopleEditor ID="peoplePickerControl1" runat="server" Width="350px" height="4px"
SelectionSet="User" /></td>
</tr>
<tr>
<td>Created For:</td>
<td><SharePoint:PeopleEditor ID="peoplePickerControl2" runat="server" Width="350" height="4px"
SelectionSet="User" MultiSelect="False" /></td>
</tr>
<tr>
<td>Company: </td>
<td><asp:TextBox ID="tbCompany" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>Office: </td>
<td><asp:TextBox ID="tbOffice" runat="server"></asp:TextBox>
</td>
</tr>
....
</table>
And the save button onClick:
protected void Button1_Click(object sender, EventArgs e)
{
SPListItemCollection listItems = web.Lists["ProblemTicket"].Items;
SPListItem pt = listItems.Add();
pt["CreatedBy"] = UserCollection1.ToString();
pt["CreatedFor"] = UserCollection2.ToString();
pt["Company"] = dpCompany.SelectedValue;
pt["Office"] = dpOffice.SelectedIndex;
....
web.AllowUnsafeUpdates = true;
pt.Update();
web.AllowUnsafeUpdates = false;
}
Any help would be highly appreciated.