질문하기질문하기
 

질문Multiple RenderAsHtml() / ctx problem

  • 2008년 3월 4일 화요일 오후 2:41NickyW 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    Hi,
    I have a web part which displays multiple lists using
    SPView.RenderAsHtml() (I need to use the RenderAsHtml rather than adding a
    ListView control since the list are not coming from the site the webpart is
    on).
    The problem I am experiencing is that the links on the item dropdown
    menu on any of the lists refer to the last list that was added! . For
    example if the web part shows 3 lists 'a','b' and 'c'  then  clicking "View
    Item" on the first item  in lists 'a' or 'b' will take me to the first item
    in list 'c'.

    After some investigation I realised this due to the fact that the links for
    a list on page are based on a Javascript "contextInfo()" object which is
    automatically generated for each list. And RenderAsHtml() always calls these
    ctx1, so each contextInfo object is overwriting the previous one!

    To solve this problem I replaced all references to ctx1 with ctxN, where N
    is an incremented integer starting at 1000 (to avaoid conflicting with other
    webparts) see code extract below:


    Code Snippet

    SPList list = web.Lists[list name];
    SPView view = list.DefaultView;
    lit = new Literal();
    lit.Text = view.RenderAsHtml();
    lit.Text =lit.Text.Replace("ctx1",string.Format("ctx{0}",N.ToString()));
    lit.Text = lit.Text.Replace("ctxId = 1", "ctxId= " +N.ToString());
    lit.Text = lit.Text.Replace("CtxNum=\"1\"", "CtxNum=\""+ N.ToString() +"\"");
    phGrid.Controls.Add(lit);

    N++;

     

     



    This seems to work fine with one problem, for some reason when you hover over the column heading and click the down arrow the filter dropdown menu is no longer displayed.

    If anyone knows how I can solve this, (or how I can tell the webpart server
    side to create a new javascript contextInfo object for each list I want to
    render I would appreciate it)

    Thanks,

    Nick