Click here to Skip to main content
15,887,596 members

Comments by yogen@softyoug (Top 1 by date)

yogen@softyoug 17-Dec-13 1:29am View    
I'm having two dropdownlist and a button.
DropDownList1 , DropDownList2 and Button1

I have done this way.
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
for (int i = 1; i <= Convert.ToInt32(DropDownList1.SelectedItem.Text); i++)
{
TextBox Answer = new TextBox();
Answer.ID = "txt" + (i).ToString();
Answer.TextMode = TextBoxMode.MultiLine;
this.FindControl("panel1").Controls.Add(Answer);
}
}

protected void Button1_Click(object sender, EventArgs e)
{
for (int i = 1; i <= Convert.ToInt32(DropDownList1.SelectedItem.Text); i++)
{
OptionsTable objOpt = new OptionsTable();
objOpt.QID = Label5.Text;
objOpt.OptionNo = i;
TextBox txtObj = new TextBox();
txtObj = (TextBox)this.FindControl("Panel1").FindControl("txt" + i.ToString());
objOpt.Options = txtObj.Text;
OptionsTableManager.Save(objOpt);
}
}

Now when i click the button1 , it throws an error "txtObj is null".

so how to solve this problem.
dropdownlist1 autopostback is true.