0

I had created a web part in Visual Studio 2010 for Sharepoint 2010. I added all the fields, implemented cascading dropdowns, custom panel and bind the data using Sharepoint SPLists

            var collection = mysite.Lists;

            SPListItemCollection valList = mysite.Lists["MyValidationList"].Items;

            ddlCompanyName.DataSource = valList.GetDataTable();

            ddlCompanyName.DataTextField = "Title";

            ddlCompanyName.DataBind();

The problem is how to handle the submit buttons.

Like after i click the submit button i want to redirect to the lists page.

Similarly how can i create the edit form like how do i know which record is being modified

Can i use querystring..

Any help is appreciated.

Please note i am not using any third party library

0

to get the url its:

string url = SPContext.Current.Site.Url + "/" + mysite.Lists["MyValidationList"].RootFolder.Url;

add the above to the button url,

as an example im creating a button and adding the url to the button click event:

METHOD 1 within create child controls

string url = SPContext.Current.Site.Url + "/" + mysite.Lists["MyValidationList"].RootFolder.Url;

Button b = new Button();
b.PostBackUrl = url;
controls.add(b);

this method is assigning the url on the creation of the button.

METHOD 2

create a global varible to hold the url:

string url = null;

create your button within creatchildcontrols event:

        Button b = new Button();
        b.Click += new EventHandler(b_Click);
        url = SPContext.Current.Site.Url + "/" + mysite.Lists["MyValidationList"].RootFolder.Url;
        controls.add(b);

now we have created a button and a click event you want to populate the url you can do like so:

    private void b_Click(object sender, EventArgs e)
    {
        Button b = sender as Button;
        b.PostBackUrl = url;
    }

this method is assigning the url on the click event of the button.

  • Thats great but can you please tell me the other part of the question that how to replace the existing/default forms for edit and create with my new webparts and how to get the record being edited. I cannot find any documentation for them – Moons Oct 30 '13 at 11:47
  • when you say edit form, you mean you want to change the default edit form when editing a list item and you want to replace it with your webpart? – Ali Jafer Oct 30 '13 at 12:21
  • Yes thats correct but all the sample i find out show steps to create a application page etc etc but then dont show how can i use my custom buttons etc. My Webpart is doing all the work itself and is not required any other facility. What i am unsure is that what will happen to the Save etc button that are in ribbon and how can i update the item being edited. I am using Sharepoint 2013 – Moons Oct 30 '13 at 12:33
  • Similarly while saving the record i am using SPListItem item = null;//valList[(Guid)]; But i am not able to find the Guid. How can i get this? While filling the form i am using .GetDataTable() and then using Select command – Moons Oct 30 '13 at 12:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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