Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to get Label value from parent repeater and use it for child repeater

How to get Label value from parent repeater and use it for child repeater

Scheduled Pinned Locked Moved C#
databasequestiondockerhelptutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dhyanga
    wrote on last edited by
    #1

    Hi, I have two repeaters Repeater1(parent repeater) and Repeater2 (nested repeater). The Repeater1 has two labels and Repeater 2 as shown.

    <HeaderTemplate>
    </HeaderTemplate>

        <%# DataBinder.Eval(Container.DataItem,"Category").ToString().Trim()%>
        <%# DataBinder.Eval(Container.DataItem,"Description").ToString().Trim() %>
    	
    		<HeaderTemplate >
    		</HeaderTemplate>
    		 
    				<%# DataBinder.Eval(Container.DataItem,"PriceRanges").ToString().Trim() %>
    

    Now I want to use Category and Description label values as a parameters for the sql query for Repeater2. How do I get those values? Please help. The code I am using is below :

    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    GetCateDescription();
    }
    }

        public void GetCateDescription(string stuID)
        {
            SqlCommand cmdList = new SqlCommand("Select distinct Category,Description from Records", cnx);
            cmdList.CommandType = CommandType.Text;
            DataSet ds = new DataSet();
            SqlDataAdapter objDA = new SqlDataAdapter(cmdList);
            objDA.Fill(ds, "Category");
            Repeater1.DataSource = ds;
            Repeater1.DataBind();  
        }
    

    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
    if (cnx.State == ConnectionState.Closed)
    {
    cnx.Open();
    }

            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                Label Category = e.Item.FindControl("Category") as Label;
                
                Repeater Repeater2 = e.Item.FindControl("Repeater2") as Repeater;
                Repeater2.DataSource =    showAllPrices(Category.Te
    
    R 1 Reply Last reply
    0
    • D Dhyanga

      Hi, I have two repeaters Repeater1(parent repeater) and Repeater2 (nested repeater). The Repeater1 has two labels and Repeater 2 as shown.

      <HeaderTemplate>
      </HeaderTemplate>

          <%# DataBinder.Eval(Container.DataItem,"Category").ToString().Trim()%>
          <%# DataBinder.Eval(Container.DataItem,"Description").ToString().Trim() %>
      	
      		<HeaderTemplate >
      		</HeaderTemplate>
      		 
      				<%# DataBinder.Eval(Container.DataItem,"PriceRanges").ToString().Trim() %>
      

      Now I want to use Category and Description label values as a parameters for the sql query for Repeater2. How do I get those values? Please help. The code I am using is below :

      protected void Page_Load(object sender, EventArgs e)
      {
      if (!IsPostBack)
      {
      GetCateDescription();
      }
      }

          public void GetCateDescription(string stuID)
          {
              SqlCommand cmdList = new SqlCommand("Select distinct Category,Description from Records", cnx);
              cmdList.CommandType = CommandType.Text;
              DataSet ds = new DataSet();
              SqlDataAdapter objDA = new SqlDataAdapter(cmdList);
              objDA.Fill(ds, "Category");
              Repeater1.DataSource = ds;
              Repeater1.DataBind();  
          }
      

      protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
      {
      if (cnx.State == ConnectionState.Closed)
      {
      cnx.Open();
      }

              if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
              {
                  Label Category = e.Item.FindControl("Category") as Label;
                  
                  Repeater Repeater2 = e.Item.FindControl("Repeater2") as Repeater;
                  Repeater2.DataSource =    showAllPrices(Category.Te
      
      R Offline
      R Offline
      Raj Mouli
      wrote on last edited by
      #2

      hi, I 've two assumptions, not sure what will fix you issues, 01. Try having a hidden variable after the label, and try getting the value from hidden Label 02. in Repeater1_ItemDataBound, rather than using e.Item.FindControl, you can do Repeater1.Items[e.Item.ItemIndex].FindControl("Category")- try this once Thanks Mouli

      Mouli

      D 1 Reply Last reply
      0
      • R Raj Mouli

        hi, I 've two assumptions, not sure what will fix you issues, 01. Try having a hidden variable after the label, and try getting the value from hidden Label 02. in Repeater1_ItemDataBound, rather than using e.Item.FindControl, you can do Repeater1.Items[e.Item.ItemIndex].FindControl("Category")- try this once Thanks Mouli

        Mouli

        D Offline
        D Offline
        Dhyanga
        wrote on last edited by
        #3

        Hidden variable worked well..

        Dhyanga

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups