By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,432 Members | 790 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,432 IT Pros & Developers. It's quick & easy.

problem with maintaining value of dynamic control

P: 29
hi all ,

i am mess with the one situation.

i am using asp.net2.0 ,C# and sql server 2005.

I have checkboxlist and based on user selection i creates dynamic controls(which code is in filterbutton_Click event and i call createcontrols function(public) in that ).But when i select value of that control(dynamic created) in another button click event(searchbutton) first it create fuction does not create dynamic control second as a result i do not get value of the control i call create function in filterbutton click and oninit()[
please help

my create function is


Expand|Select|Wrap|Line Numbers
  1. private void createcontrols()
  2. {
  3.  
  4. i = 1;
  5.  
  6. //if (CheckBoxListmst.SelectedIndex > -1)
  7.  
  8. //{
  9.  
  10. foreach (ListItem li in CheckBoxListmst.Items)
  11. {
  12.  
  13. if (li.Selected == true)
  14. {
  15.  
  16. Label label = new Label();
  17.  
  18. DropDownList dropdownlist = new DropDownList();
  19.  
  20. label.ID = "label" + i.ToString();
  21.  
  22. label.EnableViewState = true; 
  23.  
  24. dropdownlist.ID = "dropdownlist" + i.ToString();
  25.  
  26. dropdownlist.EnableViewState = true ;
  27.  
  28.  
  29. label.Text = li.Text;
  30.  
  31. //Label1.Text += dropdownlist.ID ;
  32.  
  33. i++;
  34.  
  35. //rdr = cmd.ExecuteReader();
  36.  
  37. for (int j = 0; j < 5; j++ )
  38. {
  39.  
  40. ListItem ld = new ListItem();
  41.  
  42. ld.Text = j.ToString() ;
  43.  
  44. ld.Value = j.ToString();
  45.  
  46. dropdownlist.Items.Add(ld);
  47.  
  48. }
  49.  
  50. PlaceHolder1.Controls.Add(label);
  51.  
  52. PlaceHolder1.Controls.Add(dropdownlist);
  53.  
  54.  
  55.  
  56. Response.Write("<br>");
  57.  
  58.  
  59. }
  60.  
  61. }
  62.  
  63. }
  64.  
  65. // }
  66.  
  67. }
  68.  
  69.  
and i access it with the code as
Expand|Select|Wrap|Line Numbers
  1. Label objlbl;
  2.  
  3. DropDownList objdrop;
  4.  
  5. objlbl = this.PlaceHolder1.FindControl("label1") as Label;
  6.  
  7. objdrop = this.PlaceHolder1.FindControl("dropdownlist1") as DropDownList;
  8.  
  9. if ((objlbl != null) && (objdrop.SelectedIndex > -1 ))
  10.  
  11. {
  12.  
  13. Label1.Text = objlbl.Text; //Page.FindControl("label1").ToString() ;
  14.  
  15. Label2.Text = objdrop.SelectedValue;
  16.  
  17. }
  18.  
  19.  


i call createcontrol funtion in filterbutton_click and override oninit()


thank you
Jul 27 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.