problem with maintaining value of dynamic control

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • imranabdulaziz
    New Member
    • Dec 2006
    • 29

    problem with maintaining value of dynamic control

    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_Cl ick event and i call createcontrols function(public ) in that ).But when i select value of that control(dynamic created) in another button click event(searchbut ton) 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


    [code=cpp]
    private void createcontrols( )
    {

    i = 1;

    //if (CheckBoxListms t.SelectedIndex > -1)

    //{

    foreach (ListItem li in CheckBoxListmst .Items)
    {

    if (li.Selected == true)
    {

    Label label = new Label();

    DropDownList dropdownlist = new DropDownList();

    label.ID = "label" + i.ToString();

    label.EnableVie wState = true;

    dropdownlist.ID = "dropdownli st" + i.ToString();

    dropdownlist.En ableViewState = true ;


    label.Text = li.Text;

    //Label1.Text += dropdownlist.ID ;

    i++;

    //rdr = cmd.ExecuteRead er();

    for (int j = 0; j < 5; j++ )
    {

    ListItem ld = new ListItem();

    ld.Text = j.ToString() ;

    ld.Value = j.ToString();

    dropdownlist.It ems.Add(ld);

    }

    PlaceHolder1.Co ntrols.Add(labe l);

    PlaceHolder1.Co ntrols.Add(drop downlist);



    Response.Write( "<br>");


    }

    }

    }

    // }

    }

    [/code]

    and i access it with the code as
    [code=cpp]
    Label objlbl;

    DropDownList objdrop;

    objlbl = this.PlaceHolde r1.FindControl( "label1") as Label;

    objdrop = this.PlaceHolde r1.FindControl( "dropdownlist1" ) as DropDownList;

    if ((objlbl != null) && (objdrop.Select edIndex > -1 ))

    {

    Label1.Text = objlbl.Text; //Page.FindContro l("label1").ToS tring() ;

    Label2.Text = objdrop.Selecte dValue;

    }

    [/code]



    i call createcontrol funtion in filterbutton_cl ick and override oninit()


    thank you
    Last edited by Frinavale; Jul 27 '07, 02:31 PM. Reason: Added [code] tags to make more legible
Working...