Click here to Skip to main content
15,996,848 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have used two dropdown list inside repeater control of asp.net. I want to retain selected value of drop down which i selected before postback of the page.Please suggest what would be solution.



I have used this code inside itemdatabound events of repeter controls.

my code below:-

What should be add in this event to retaining the selected value after posting the page of dropdown list inside repeater contorols.
C#
 protected void rptCustomers_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
                        DropDownList drplist = e.Item.FindControl("drpList") as DropDownList;
                        DropDownList drpSublist = e.Item.FindControl("drpSubcategory") as DropDownList;
 cmd.CommandType = CommandType.Text;
                        con.Open();
                        SqlDataReader idr = cmd.ExecuteReader();
                        DataTable dtcat = new DataTable();

                        dtcat.Load(idr);
                        if (dtcat.Rows.Count > 0)
                        {       
                            drplist.DataSource = dtcat;
                            drplist.DataValueField = "description";
                            drplist.DataTextField = "description";
                            drplist.DataBind();
                            idr.Close();
                            con.Close();
                        }    


 SqlDataReader idr2 = cmd.ExecuteReader();
                        DataTable dtcat2 = new DataTable();
                        dtcat2.Load(idr2);
                        if (dtcat.Rows.Count > 0)
                        {
                            drpSublist.DataSource = dtcat2;
                            drpSublist.DataValueField = "description";
                            drpSublist.DataTextField = "description";
                            drpSublist.DataBind();
                            idr.Close();
                            con.Close();
                        }
}


please suggest some solution of retaing selected value of dropdown list inside repeter after postback.

Thanks and regard.
Posted
Updated 23-Nov-14 21:46pm
v2

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