ZoneIndex

Last post 05-14-2004 1:56 PM by mharder. 7 replies.

Sort Posts:

  • ZoneIndex

    04-09-2004, 8:10 PM
    • Member
      287 point Member
    • horatio05
    • Member since 12-09-2003, 1:04 AM
    • Posts 61
    I see that they removed the ZoneIndex property from the WebParts in VS2005. My question is how are we supposed to get this ZoneIndex if we want to use the WebPartManager's MoveWebPart() function? I guess I could just cycle through a Zone's webParts until I find it, but that seems terribly inefficient. Are there any plans to address this? Thanks.
  • Re: ZoneIndex

    04-10-2004, 3:24 AM
    • All-Star
      29,644 point All-Star
    • Fredrik N
    • Member since 06-22-2002, 5:03 AM
    • Sweden
    • Posts 5,334
    • TrustedFriends-MVPs
    The zoneIndex in the MoveWebPart() method will be used to specify where in the zone the webpart should be placed. For example, if you have 3 webparts in one zone, and you want to change the order of the webparts, you use the ZoneIndex.

    For example the following code will move the first webparts in the first zone, and place it after the second webpart in the zone:

    Webpartmanager1.MoveWebPart(Webpartmanager1.WebParts[0], Webpartmanager1.Zones.Item[0], 2)

    If you want the webpart to be at the top of the zone, you will change the zone index to 0.

    So there is no need to iterate through all of the zones to move a webpart to a specific zone.
    /Fredrik Normén - fredrikn @ twitter

    ASPInsider

    Microsoft MVP, MCSD, MCAD, MCT

    ASPInsiders
    My Blog
  • Re: ZoneIndex

    04-12-2004, 7:52 PM
    • Member
      287 point Member
    • horatio05
    • Member since 12-09-2003, 1:04 AM
    • Posts 61
    But I want to move the webpart within its own zone, up or down, so I need to either increment or decrement that webpart's current ZoneIndex. In the scenario you are using I would have to know before hand where in the zone the webpart resides and where I want to move the webpart, but that is not always the case, especially if the user has the ability to drag and move the webparts around. I think they should keep the zoneindex property in the webparts or have some way of reaching it.
  • Re: ZoneIndex

    04-13-2004, 12:43 AM
    • All-Star
      29,644 point All-Star
    • Fredrik N
    • Member since 06-22-2002, 5:03 AM
    • Sweden
    • Posts 5,334
    • TrustedFriends-MVPs
    Here is an example where you can get the zoneindex, maybe it's not so nice, but it will work:


    Int index = Webpartmanager1.Zones.Item[0].WebParts.IndexOf((Webpartmanager1.WebParts.Item[0]));

    index = index + 1;

    Webpartmanager1.MoveWebPart(Webpartmanager1.WebParts.Item[0], Webpartmanager1.Zones.Item[0], index);


    /Fredrik Normén - fredrikn @ twitter

    ASPInsider

    Microsoft MVP, MCSD, MCAD, MCT

    ASPInsiders
    My Blog
  • Re: ZoneIndex

    04-13-2004, 1:55 AM
    • All-Star
      29,644 point All-Star
    • Fredrik N
    • Member since 06-22-2002, 5:03 AM
    • Sweden
    • Posts 5,334
    • TrustedFriends-MVPs
    Here is a better example:


    WebPartZoneBase myZone = Webpartmanager1.Zones["myZone"];
    WebPart myWebPart = myZone.WebParts["myWebpart"];

    int zoneIndex = myZone.WebParts.IndexOf(myWebPart);

    zoneIndex++;

    Webpartmanager1.MoveWebPart(myWebPart, myZone, zoneIndex);
    /Fredrik Normén - fredrikn @ twitter

    ASPInsider

    Microsoft MVP, MCSD, MCAD, MCT

    ASPInsiders
    My Blog
  • Re: ZoneIndex

    04-13-2004, 1:56 AM
    • Member
      287 point Member
    • horatio05
    • Member since 12-09-2003, 1:04 AM
    • Posts 61
    It's not the prettiest solution I've ever used, but it's certainly not the ugliest :)
    Thanks!
  • Re: ZoneIndex

    04-28-2004, 1:48 PM
    • All-Star
      29,644 point All-Star
    • Fredrik N
    • Member since 06-22-2002, 5:03 AM
    • Sweden
    • Posts 5,334
    • TrustedFriends-MVPs
    In the Beta, Microsoft will probably add a public ZoneIndex property to the WebPart class.
    /Fredrik Normén - fredrikn @ twitter

    ASPInsider

    Microsoft MVP, MCSD, MCAD, MCT

    ASPInsiders
    My Blog
  • Re: ZoneIndex

    05-14-2004, 1:56 PM
    • Contributor
      4,557 point Contributor
    • mharder
    • Member since 11-22-2002, 7:03 AM
    • Redmond, WA
    • Posts 917
    • AspNetTeam
      Moderator
    Yes, I can confirm that there will be a get-only WebPart.ZoneIndex property in the Beta. You still need to call WebPartManager.MoveWebPart() to change the ZoneIndex.
    http://blogs.msdn.com/mharder

    This posting is provided "AS IS" with no warranties, and confers no rights.
Page 1 of 1 (8 items)