none
datalist nesting problem......urgent help RRS feed

  • Question

  • hey all,

    i'm using nested datalist to show category hierarchy....

    my requirement is...

    when i click on first level datalist if it has subcategories belongs to it..then datalist 2 should displayed containing its subcategories.....

    i have made visible false for datalist leve 2......and coding using itemdatabound event.but if visible is set to true then subcategories displays for every item in first datalist...

    but i want to display subcategory only for its main category...

    the datalists are placed on master page...and books related to those category are being dispalyed on one of its content page..

    but when page redirects i want to remain expanded the current selected item........

    but it gets collapse......

    help me........

    this is code i'm using

     

     

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                  <ContentTemplate>
                    <asp:DataList ID="DatLstCat" runat="server" DataSourceID="OdsCat" DataKeyField="catcod"
                      OnItemCommand="DatLstCat_ItemCommand">
                      <ItemTemplate>
                        <li style="margin-left: 36px">
                          <asp:LinkButton ID="lnkbtncat" Text='<%#Eval("catnam") %>' CommandName="CatBooks"
                            ForeColor="Black" Font-Underline="false" runat="server"></asp:LinkButton>
                          <%--(<%#Count(Convert.ToInt32(Eval("catcod"))) %>)--%>
                          <br />
                        </li>
                        <%------------Level 2 Begins------------%>
                        <%-- <asp:UpdatePanel ID="upd2" runat="server"><ContentTemplate>--%>
                        <asp:DataList ID="DatLstCatLev2" runat="server" DataSourceID="OdsCatLev2" DataKeyField="catcod"
                          OnItemCommand="DatLstCatLev2_ItemCommand" Visible="false">
                          <ItemTemplate>
                            <li style="margin-left: 54px">
                              <asp:LinkButton ID="lnkbtncat0" Text='<%#Eval("catnam") %>' CommandName="CatBooks"
                                ForeColor="Black" Font-Underline="false" runat="server"></asp:LinkButton>
                              (<%#Count(Convert.ToInt32(Eval("catcod"))) %>)
                              <br />
                            </li>
                          </ItemTemplate>
                        </asp:DataList>
                        <%--  </ContentTemplate></asp:UpdatePanel>--%>
                        <asp:ObjectDataSource ID="OdsCatLev2" runat="server" SelectMethod="DspCatByParCat"
                          TypeName="clscat">
                          <SelectParameters>
                            <asp:SessionParameter Name="catcod" SessionField="catcod2" Type="Int32" />
                          </SelectParameters>
                        </asp:ObjectDataSource>
                        <%-------------Level 2 Ends-------------%>
                      </ItemTemplate>
                    </asp:DataList>
                  </ContentTemplate>
                </asp:UpdatePanel>
                <asp:ObjectDataSource ID="OdsCat" runat="server" SelectMethod="DspParCat" TypeName="clscat">
                </asp:ObjectDataSource>
    

    --------------------------------------------------------------------------------------------------------------------
    code behind code is
    --------------------------------------------------------------------------------------------------------------------
     protected void DatLstCat_ItemCommand(object source, DataListCommandEventArgs e)
      {
        if (e.CommandName == "CatBooks")
        {
          if (Session["DatLstPrvLev2"] != null)
          {
            DataList DatLstPrvLev2 = (DataList)(DatLstCat.Items[Convert.ToInt32(Session["DatLstPrvLev2"])].FindControl("DatLstCatLev2"));
            DatLstPrvLev2.Visible = false;
          }
    
          if (objcat.DspSubCat(Convert.ToInt32(DatLstCat.DataKeys[e.Item.ItemIndex])).Count == 0)
          {
            Response.Redirect("BooksByCat.aspx?catcod=" + DatLstCat.DataKeys[e.Item.ItemIndex]);        
           //Server.Transfer("BooksByCat.aspx?catcod=" + DatLstCat.DataKeys[e.Item.ItemIndex]);
    
          }
          else
          {
            if (Convert.ToInt32(Session["DatLstPrvLev2"]) == e.Item.ItemIndex && Session["DatLstPrvLev2"] != null)
            {
              DataList DatLstPrvLev2 = (DataList)(DatLstCat.Items[Convert.ToInt32(Session["DatLstPrvLev2"])].FindControl("DatLstCatLev2"));
             // DatLstPrvLev2.Visible = false;
              Session["DatLstPrvLev2"] = null;
            }
            else
            {
              Session["catcod2"] = DatLstCat.DataKeys[e.Item.ItemIndex];
              DataList DatLstCatLev2 = (DataList)(DatLstCat.Items[e.Item.ItemIndex].FindControl("DatLstCatLev2"));
              DatLstCatLev2.Visible = true;
              Session["DatLstLev2"] = DatLstCatLev2;
              Session["DatLstPrvLev2"] = e.Item.ItemIndex;
            }
          }
        }    
      }
      protected void DatLstCatLev2_ItemCommand(object source, DataListCommandEventArgs e)
      {
        if (e.CommandName == "CatBooks")
        {
          DataList DatLstCatLev2 = (DataList)(Session["DatLstLev2"]);
          if (objcat.DspSubCat(Convert.ToInt32(DatLstCatLev2.DataKeys[e.Item.ItemIndex])).Count == 0)
          {
           Response.Redirect("BooksByCat.aspx?catcod=" + DatLstCatLev2.DataKeys[e.Item.ItemIndex]);       
            
           //DatLstCatLev2.DataSource = Session["DatLstLev2"];
           //DatLstCatLev2.DataBind();
           //  Server.Transfer("BooksByCat.aspx?catcod=" + DatLstCatLev2.DataKeys[e.Item.ItemIndex]);
          }
        }
      }

    please help................

     


    Best Regards :
    -----------------
    Mayank Pathak
    Saturday, November 13, 2010 7:53 AM

Answers