<asp:Repeater ID="PrescriptionRepeater" runat="server">
<ItemTemplate>
<asp:DropDownList runat="server" ID="ddlStatus" OnSelectedIndexChange="ddlStatus_SelectedIndexChanged" autopostback="true">
<asp:ListItem Text="Prescribed"></asp:ListItem>
<asp:ListItem Text="Cancelled"></asp:ListItem>
<asp:ListItem Text="Lost"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:Repeater>
I have Placed a DropDownList(id="ddlStatus") in a DataRepeater and set
OnSelectedIndexChange="ddlStatus_SelectedIndexChanged" autopostback="true". Now when I run the Page and change selected index of drop down list, it posts back but does not run the method ddlStatus_SelectedIndexChanged .
Then I have tried to register the Event by Hard coding.
ddlStatus.SelectedIndexChanged += new EventHandler(ddlStatus_SelectedIndexChanged);But still there is no change. Finally, my senior coleage find out a solution
That is Page.Request.Params.Get("__EVENTTARGET") . This method returns name of the control that caused PostBack. Then what we did was, find that control and call a method for further processing
if (Page.IsPostBack)
{
DropDownList ddlStatus = (DropDownList)Page.FindControl(Page.Request.Params["__EVENTTARGET"]);
if (ddlStatus != null)
{
DDLStateSelectedIndexChangedEvent(ddlStatus);
}
}
*I have not checked yet what to do If you have more than one dropdownlist causing Postback in a single row of DataRepeater.
*Tested on Visual Studio 2005 and .Net 2.0
Want to know details? click below
Determining the Control that Caused a PostBack


