SharePoint - pass data from one web part to another

Asked By Bookworm on 10-Jan-12 03:48 AM
Hi,

I have a SPGrid on my webpart1, and i need that in the moment that i click one record of the grid, the details of that row, to be shown in another page? how can i pass the data? from one webpart to another?

thnx
Riley K replied to Bookworm on 10-Jan-12 03:55 AM


Not sure , did u try passing through query string to another page that contains webpart

One more thing is that you can connect two webparts the new feature, try it

You can pass data between them

By using menus and dialog boxes, you can connect Web Parts, pass data between them, and synchronize their behavior.

  1. Browse to the page that contains the two Web Parts you want to connect.
  2. On the Site Actions menu Site Actions menu, click Edit Page.
  3. From either one of the Web Parts, click the Web Part menu. Then, point to Connections, and point to the kind of connection that you want to create or change, such as Provide Row To or Get Sort/Filter From. Click the name of the Web Part for which you want to create or change a connection.

    http://office.microsoft.com/en-us/sharepoint-server-help/connect-data-in-web-parts-HA101785157.aspx#_Toc287442204

Regards
D Company replied to Bookworm on 10-Jan-12 03:57 AM
end of post
D Company replied to D Company on 10-Jan-12 03:59 AM

Hello Friend,

using code you can impliment this

To implement this functionality between WebParts, you  should create an Interface .This interface will be implemented by both the provider and consumer classes.

 

 

 Interface : 

  
    public interface Test
    {
      string Name { get; set; }
    }

 

 

Provider class :

 

    public class Provider : WebPart, Test
    {
      TextBox tb = new TextBox();
      Button btn = new Button();

      string _Name = "";

 

      public string Name
      {
        get{return _Name;}
        set{_Name = value;}
      }    
     
      protected override void CreateChildControls()
      {
        btn.Text = "Show";
        btn.Click += new EventHandler(btn_Click);

        tb.Text = "Prem";
        Name = tb.Text;

        this.Controls.Add(tb);
        this.Controls.Add(btn);
      }
      protected override void Render(HtmlTextWriter writer)
      {
        EnsureChildControls();
        RenderChildren(writer);
 
      }
      void btn_Click(object sender, EventArgs e)
      {
        Name = tb.Text;
      }
   
      [ConnectionProvider("Test Provider")]
      public Test ProvideCommunication()
      {
        return this as Test;
      }  

    }

Consumer class:

 

   public class Consumer : WebPart
    {
      private Test providerWebPart;

 

      [ConnectionConsumer("Test Consumer")]
      public void ReceiveName(Test  provider)
      {
        providerWebPart = provider;
      }

      protected override void Render(HtmlTextWriter writer)
      {
        if (providerWebPart != null)
          writer.Write("Value provided is : " + providerWebPart.Name);

        base.Render(writer);
      }
    }

 

 

kalpana aparnathi replied to Bookworm on 10-Jan-12 02:49 PM

Create or change a connection between two Web Parts

By using menus and dialog boxes, you can connect Web Parts, pass data between them, and synchronize their behavior.

  1. Open the Web Part Page.
  1. On the Site Actions menu Site Actions menu, click Edit Page.
  1. Decide which two Web Parts you want to connect. You can create or change the same connection by starting from either Web Part.
  2. From either one of the Web Parts, click the Web Part menu Web Part Edit Menu, point to Connections, point to the type of connection that you want to create or change, such as Provide Row To or Get Sort/Filter From, and then click the name of the Web Part for which you want to create or change a connection.

The Web Part menu may not be enabled or visible on your Web Part Page for several reasons, including that the Web Part or the zone does not support connections, you are using a browser that is not compatible with Windows SharePoint Services, or connections are disabled on your site.

  1. For some Web Part connections, you might need to select additional information in the Configure Connection dialog box. For example, you might need to select the connection type that you want to use or a column that you want to filter. Also, depending on how one or both of the Web Parts were created, you may see additional dialog boxes that are unique to the Web Part connection. For more information, see the Help information, if any, for the custom Web Part.

 Tip   You can hide a Web Part if you want to use it to provide data to another Web Part through a Web Part connection, but you don't want to display the Web Part.



http://msdn.microsoft.com/en-us/library/ms469765.aspx