Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi guys,

I have user control which contains:
one dropdownlist n a textbox.

i have to populate the dropdownlist in the user control n have to write the "onselectedindexchange" to fill the textbox which in the user control it self., event.

n

i'm placing this web user control in a repeater in ASP.NET.

i tried hard to populate the dropdownlist in the cs file of the user control
but its not working.

Plzzz give some suggestions/help me...

protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            int index = 0;
            if (Repeater1.Items[index].ItemType == ListItemType.Item || Repeater1.Items[index].ItemType == ListItemType.AlternatingItem)
            {
                if (Repeater1.Items[index].FindControl("Repeater2") != null)
                {

                    Repeater r = Repeater1.Items[index].FindControl("Repeater2") as Repeater;

                    foreach (RepeaterItem item in r.Items)
                    {
                        UserControl u = (UserControl)item.FindControl("SubChemicals1");

                        if (u != null)
                        {

                            //if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                            //{
                                DropDownList d = (DropDownList)u.FindControl("ddlchemicals");
                                d.DataTextField = "CName";
                                d.DataValueField = "RecID";
                                d.DataSource = bl.Fill_DDL("Sp_GetSubChemicals");
                                d.DataBind();
                                d.Items.Insert(0, new ListItem("---Select---", "0"));

                                
                            //}
                        }

                    }
                }
            }
        }


I got it, but the things is, i have morethan one nested repeaters
where this dropdownlist is located n
its filling only in the 1st nested repeater only but not other repeaters....

Thanks
Posted
Updated 22-Apr-14 4:11am
v5
Comments
Karthik Harve 22-Apr-14 4:54am    
can you show us some of your code that you have tried ? Did you tried to find the user control on Data Bound event of the repeater ? show your code, so that we could guide you easily.
abdul subhan mohammed 22-Apr-14 5:41am    
plz check...
Sunasara Imdadhusen 22-Apr-14 6:32am    
Hey can you please let us know what does it mean "Not working" are you getting any error?
abdul subhan mohammed 22-Apr-14 9:34am    
i have updated the code, which i tried,
with this code, i'm able to fill the dropdownlist but its filling only for the 1st nested repeater, where i have more than one nested repeater,
i'm not getting any error... but the problem is, its not filling/populating the dropdownlist in all the nested repeaters.

plz do check n suggest me ...

thnx
Syed Shakeer Hussain 22-Apr-14 13:11pm    
Hi Subhan,
If below solution not workout please check this link
http://stackoverflow.com/questions/1432790/populating-dropdownlist-inside-repeater-not-working?rq=1

int index = 0;

It explains your issue.
I also feel like you got the ItemDataBound event all wrong.

C#
protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType != ListItemType.Item
                && e.Item.ItemType != ListItemType.AlternatingItem)
            {
                return;
            }


            UserControl u = (UserControl)e.item.FindControl("SubChemicals1");

            if (u != null)
            {

                    DropDownList d = (DropDownList)u.FindControl("ddlchemicals");
                    d.DataTextField = "CName";
                    d.DataValueField = "RecID";
                    d.DataSource = bl.Fill_DDL("Sp_GetSubChemicals");
                    d.DataBind();
                    d.Items.Insert(0, new ListItem("---Select---", "0"));


            }


        }
 
Share this answer
 
XML
Hi Subhan, Please try with this code

<pre lang="c#">protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType != ListItemType.Item
                && e.Item.ItemType != ListItemType.AlternatingItem)
 UserControl u = (UserControl)e.item.FindControl("SubChemicals1");

            if (u != null)
            {

                    DropDownList d = (DropDownList)u.FindControl("ddlchemicals");
                    d.DataTextField = "CName";
                    d.DataValueField = "RecID";
                    d.DataSource = bl.Fill_DDL("Sp_GetSubChemicals");
                    d.DataBind();
                    d.Items.Insert(0, new ListItem("---Select---", "0"));
             }

        }</pre>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900