I have a dropdown list inside a asp:repeater item template. how can I get its value on button click event.
Assuming that BtnSave
is also inside the repeater.
You get the RepeaterItem
by casting the button's NamingContainer. Then you can use FindControl
to get the reference to your DropDownList
:
protected void BtnSaveClick(object sender, EventArgs e) {
var btn = (Button)sender;
var item = (RepeaterItem)btn.NamingContainer;
var ddl = (DropDownList) item.FindControl("ddlWorkflowMembers");
// ...
}
If the button is outside of the repeater and you want to save all items, you need to loop through all:
protected void BtnSaveClick(object sender, EventArgs e) {
foreach(RepeaterItem item in WorkflowListAfter.Items)
{
var ddl = (DropDownList) item.FindControl("ddlWorkflowMembers");
// ...
}
}