How to get Label value from parent repeater and use it for child repeater
-
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
-
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
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
-
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