Monday, March 26, 2012

trigger for control that is dynamically created on databind

I have a dropdownlist that is created when the gridview is databound. This is because the dropdownlist is contained in the headertemplate of a templatefield column. So I have tried to add the trigger dynamically right after the gridview is databound, but I keep getting an error saying that the controlID wasn't found...I don't know what is wrong. I can find the control inside the the gridview with no problem using the findControl fuction.


TimeStampGridView.DataBind();
DropDownList StatusFilterDLL=(DropDownList)TimeStampGridView.HeaderRow.Cells[2].FindControl("StatusFilter");//finds the Control
StatusFilterDLL.SelectedIndex = StatusFilterDLL.Items.IndexOf(StatusFilterDLL.Items.FindByText(StatusFilter));//Works fine
AsyncPostBackTrigger trigger =new AsyncPostBackTrigger();
trigger.ControlID ="StatusFilter";
trigger.EventName ="SelectedIndexChanged";
GridUpdatePanel.Triggers.Add(trigger);//error:A control with ID 'StatusFilter' could not be found for the trigger in UpdatePanel 'GridUpdatePanel'


Anyone know what I'm doing wrong here?

Thanks for the help in advance!

I removed all the code for the dynamic trigger and set the dropdownlist's autopostback= true so now when the user changes the selectedindex the gridview is updated

No comments:

Post a Comment