Dear All,
I am mess with one situation let me explain the scenario.
I am making search form where I display 15 field in checkboxlist and user select one or two or three or any no to all field. Depending on his selection (he tick the field and click filter button ) Now in filter button click I create label and dropdownlist control(populat ed from database) and add it to placeholder control. Now I select value and click the search button. Now in search button I need to access those control and its selected value(ie label and droplistbox ).
I have made function to create label and dropdownlistbox which is
private void createcontrols( )
{
foreach (ListItem li in CheckBoxListmst .Items)
{
if (li.Selected == true)
{
//code added to fetch dropdownlist
setting = ConfigurationMa nager.Connectio nStrings["StyleSearchCon nectionString"];
if (setting != null)
{
Code to access data for populating dropdownlistbox
try
{
// added controls
Label label = new Label();
DropDownList dropdownlist = new DropDownList();
label.ID = "label" + i.ToString();
dropdownlist.ID = "dropdownli st" + .ToString();
i++;
rdr = cmd.ExecuteRead er();
while (rdr.Read())
{
Items for dropdownlist
}
PlaceHolder1.Co ntrols.Add(labe l);
PlaceHolder1.Co ntrols.Add(drop downlist);
}
catch (SqlException ex)
{
}
Now this create function I call in one in filter button click event and second as
protected override void OnLoad(EventArg s e)
{
base.OnLoad(e);
createcontrols( );
}
Now in seach button click event when I am trying to access
Code is
Label objlbl;
DropDownList objdrop;
objlbl = this.Page.FindC ontrol("label1" ) as Label;
objdrop = this.Page.FindC ontrol("dropdow nlist1") as DropDownList;
if ((objlbl != null) && (objdrop != null))
{
cmd.Parameters. Add("@para1", SqlDbType.VarCh ar).Value = objlbl.Text; //Page.FindContro l("label1").ToS tring() ;
cmd.Parameters. Add("@value1", SqlDbType.VarCh ar).Value = objdrop.Selecte dValue;
}
I am getting objlbl and objdrop as null.
Please help
thanks
I am mess with one situation let me explain the scenario.
I am making search form where I display 15 field in checkboxlist and user select one or two or three or any no to all field. Depending on his selection (he tick the field and click filter button ) Now in filter button click I create label and dropdownlist control(populat ed from database) and add it to placeholder control. Now I select value and click the search button. Now in search button I need to access those control and its selected value(ie label and droplistbox ).
I have made function to create label and dropdownlistbox which is
private void createcontrols( )
{
foreach (ListItem li in CheckBoxListmst .Items)
{
if (li.Selected == true)
{
//code added to fetch dropdownlist
setting = ConfigurationMa nager.Connectio nStrings["StyleSearchCon nectionString"];
if (setting != null)
{
Code to access data for populating dropdownlistbox
try
{
// added controls
Label label = new Label();
DropDownList dropdownlist = new DropDownList();
label.ID = "label" + i.ToString();
dropdownlist.ID = "dropdownli st" + .ToString();
i++;
rdr = cmd.ExecuteRead er();
while (rdr.Read())
{
Items for dropdownlist
}
PlaceHolder1.Co ntrols.Add(labe l);
PlaceHolder1.Co ntrols.Add(drop downlist);
}
catch (SqlException ex)
{
}
Now this create function I call in one in filter button click event and second as
protected override void OnLoad(EventArg s e)
{
base.OnLoad(e);
createcontrols( );
}
Now in seach button click event when I am trying to access
Code is
Label objlbl;
DropDownList objdrop;
objlbl = this.Page.FindC ontrol("label1" ) as Label;
objdrop = this.Page.FindC ontrol("dropdow nlist1") as DropDownList;
if ((objlbl != null) && (objdrop != null))
{
cmd.Parameters. Add("@para1", SqlDbType.VarCh ar).Value = objlbl.Text; //Page.FindContro l("label1").ToS tring() ;
cmd.Parameters. Add("@value1", SqlDbType.VarCh ar).Value = objdrop.Selecte dValue;
}
I am getting objlbl and objdrop as null.
Please help
thanks
Comment