Reputation: 49
I have a DropDownList
inside a repeater and whenever the selected text is changed, I have to show it in a TextBox
but I'm getting Object reference not set to an instance of an object
error
protected void Ddl_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddl = (DropDownList) sender;
RepeaterItem item = (RepeaterItem) ddl .NamingContainer;
TextBox txt = (TextBox) item.FindControl("TextBox4");
txt.Text = ddl.SelectedItem.Text;
}
Upvotes: 0
Views: 239
Reputation: 123
Just enable Ddl dropdowns autopost back property to true and just add following line of code:
protected virtual void RepeaterItemCreated(object sender, RepeaterItemEventArgs e)
{
DropDownList MyList = (DropDownList)e.Item.FindControl("ddl");
MyList.SelectedIndexChanged += ddl_SelectedIndexChanged;
}
protected void Ddl_SelectedIndexChanged(object sender, EventArgs e)
{
RepeaterItem item = (RepeaterItem) Page.FindControl("repeatorid");
TextBox txt = (TextBox) item.FindControl("TextBox4");
txt.Text = ddl.SelectedItem.Text;
}
Upvotes: 1