7

I am new to SharePoint and I have created several custom lists. I would like to use visual studio 2010 to create new EDIT/NEW/DISPLAY forms for this list. I can't seem to find anything on the internet explaining how to design these new forms with Visual Studio 2010. I would like for some guidance on how this can be done. I simply want to change the UI of the forms and make it look pretty using JQuery and that is the only purpose I have.

<?xml version="1.0" encoding="utf-8"?>

</Fields>
<Views>
  <View BaseViewID="0" Type="HTML" MobileView="TRUE" TabularView="FALSE">
    <Toolbar Type="Standard" />
    <XslLink Default="TRUE">main.xsl</XslLink>
    <RowLimit Paged="TRUE">30</RowLimit>
    <ViewFields>
      <FieldRef Name="LinkTitleNoMenu"></FieldRef>
    </ViewFields>
    <Query>
      <OrderBy>
        <FieldRef Name="Modified" Ascending="FALSE"></FieldRef>
      </OrderBy>
    </Query>
    <ParameterBindings>
      <ParameterBinding Name="AddNewAnnouncement" Location="Resource(wss,addnewitem)" />
      <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
      <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_ONET_HOME)" />
    </ParameterBindings>
  </View>
  <View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="$Resources:core,objectiv_schema_mwsidcamlidC24;" DefaultView="TRUE" MobileView="TRUE" MobileDefaultView="TRUE" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/generic.png" Url="AllItems.aspx">
    <Toolbar Type="Standard" />
    <XslLink Default="TRUE">main.xsl</XslLink>
    <RowLimit Paged="TRUE">30</RowLimit>
    <ViewFields>
      <FieldRef Name="Attachments"></FieldRef>
      <FieldRef Name="LinkTitle"></FieldRef>
    </ViewFields>
    <Query>
      <OrderBy>
        <FieldRef Name="ID"></FieldRef>
      </OrderBy>
    </Query>
    <ParameterBindings>
      <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
      <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" />
    </ParameterBindings>
  </View>
</Views>
<Forms>
  <Form Type="DisplayForm" Url="DispForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
  <Form Type="EditForm" Url="EditForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
  <Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
</Forms>

3
  • Have you seen sharepoint.stackexchange.com/questions/7417/… ?
    – eirikb
    Commented Sep 26, 2012 at 19:00
  • Yeah I actually came across this post several times and I am having a hard time trying to perform the same actions. I simply would like to create new forms for the custom list definition I created In VS2010. Are there any standard documentation explaining the correct "non-hack" way of creating forms. Commented Sep 26, 2012 at 19:12
  • To make it real simple. I would like a tutorial that can show me how to create a list definition with all views from within Visual Studio without copying and pasting generated code. I know there is a formal way on how to do custom lists and forms from vs2010 without "hacks" Commented Sep 26, 2012 at 19:55

3 Answers 3

4

There are Two ways u set your application page as List Default New/Edit/Display Form.

  1. Check This http://ikarstein.wordpress.com/2010/12/29/walkthrough-create-custom-sharepoint-2010-list-form-for-deployment-in-a-visual-studio-2010-project/

  2. also in schema of your custom list definition add this after FieldRefs

     <XmlDocuments>
    <XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
      <FormTemplates xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
        <Display>ListForm</Display>
        <Edit>ListForm</Edit>
        <New>ListForm</New>
      </FormTemplates>
    </XmlDocument>
    <XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
      <FormUrls xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
        <Edit>HERE IS THE URL OF YOUR CUSTOM PAGE</Edit>            
      </FormUrls>
    </XmlDocument>
     </XmlDocuments>
    
9
  • That was all I needed one more question under the <FormTemplates> node do I specify just the name of the form. and then it uses the FormUrls tag to reference the actual form. Could you post an example of those tabs populated. I really appreciate your help and I will mark your answer as the answer because it answered my question. Commented Sep 27, 2012 at 17:13
  • Here is my list schema here I don't see how to implement your code. Commented Sep 27, 2012 at 18:29
  • see This screencast.com/t/Tr5shVtu5ZVv Commented Sep 28, 2012 at 5:07
  • Does that go into the Schema file. I see field references under the content type node. But in schema there is a <Fields> and a <ViewFields> node so when I add my content type to the schema should it have field references also. What about the <Forms> tag should this be deleted Commented Sep 28, 2012 at 13:03
  • Thank you once again you are really helping me grasp this I am new to sharepoint but not .NEt Commented Sep 28, 2012 at 13:04
3
  var list = SPContext.Current.Web.Lists[new Guid(Request.QueryString["list"])];
                var itemId = 0;
                if (string.IsNullOrEmpty(Request.QueryString["id"]) == false)
                {
                    int.TryParse(Request.QueryString["id"], out itemId);
                }
                SPListItem listItem = null;
                if (itemId == 0)
                {
                    listItem = list.AddItem();
                }
                else
                {
                    listItem = list.GetItemById(itemId);
                }
String TaskTitle = Convert.ToString(txtTitle.Text);
            String TaskFrequency = ddlTaskFrequency.SelectedItem.Text;
 listItem["Title"] = TaskTitle;
 listItem["TaskFrequency"] = TaskFrequency;
 listItem.Update();
            Context.Response.Write("<script language='javascript'> window.frameElement.commitPopup();</script>");
            Context.Response.Flush();
            Context.Response.End();

If you are using same aspx page then in edit form you have to load like this.

private void LoadData()
        {
            var list = SPContext.Current.Web.Lists[new Guid(Request.QueryString["list"])];
            var itemId = 0;
            if (string.IsNullOrEmpty(Request.QueryString["id"]) == false)
            {
                int.TryParse(Request.QueryString["id"], out itemId);
            }
            if (itemId != 0)
            {
                var listItem = list.GetItemById(itemId);
                ddlNotificationType.SelectedIndex = ddlNotificationType.Items.IndexOf(ddlNotificationType.Items.FindByText((listItem["NotificationType"] == null) ? string.Empty : listItem["NotificationType"].ToString()));
                txtTitle.Text = (listItem["Title"] == null) ? string.Empty : listItem["Title"].ToString();
                ddlTaskFrequency.SelectedIndex = ddlTaskFrequency.Items.IndexOf(ddlTaskFrequency.Items.FindByText((listItem["TaskFrequency"] == null) ? string.Empty : Convert.ToString(listItem["TaskFrequency"])));
}

and in your aspx page form load call this method

if (!Page.IsPostBack)


LoadData();           {
}
1
  • This so beautifully explained you have just unleashed some new capabilities that I needed so bad. Now I can easily create a master detail form for my list items. I have had a very hard time creating the master/detail type forms. Commented Aug 14, 2013 at 13:53
1

Below is a beautiful step by step article posted. Kindly go through the same.

(http://ranaictiu-technicalblog.blogspot.in/2011/06/sharepoint-custom-addeditdisplay-form.html)

Thanks, Sandy

3
  • This is great I ended up using Jquery but I will be able to get a lot more functionality this way. Is the SharePoint server Object model available to the aspx page and can you access the controls for each field. Commented Aug 13, 2013 at 19:07
  • Yes you can use share point object model to the aspx page.For example if you want to add the items which you have entered in aspx page to a list you can use th ebelow code. Commented Aug 14, 2013 at 9:57
  • i have posted the code above Commented Aug 14, 2013 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.