我试图在DropDownList的选定索引更改中获取所选文本。这是模拟了。
<pre>
<ItemTemplate>
<tr>
<td><%# Eval("Teaenter code herem_Name")%></td>
<td class="text-center"><a href="http://localhost:4886/Payments/<%#Eval("Team_Payment")%>">View</a></td>
<td>
<asp:DropDownList ID="drlApplicationStatus" runat="server" AutoPostBack="true" CssClass="form-control" CommandName="Update" CommandArgument='<%#Eval("Team_ID")%>'OnSelectedIndexchanged="Selected_IndexChanged" >
<asp:ListItem CssClass="text-center" Text="--Select--" Value="0"></asp:ListItem>
<asp:ListItem CssClass="text-center" Text="Active" Value="1"></asp:ListItem>
<asp:ListItem CssClass="text-center" Text="Pending" Value="2 "></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</ItemTemplate>
</pre>
protected void TeamList_ItemCommand(object source, RepeaterCommandEventArgs e)
{
DropDownList drlApplicationStatus = (DropDownList)source;
if (drlApplicationStatus.SelectedIndex == 1 && e.CommandArgument !=null)
{
Teams.UpdateTeamStatus(int.Parse(e.CommandArgument.ToString()), "Active");
}
else if(drlApplicationStatus.SelectedIndex == 2 && e.CommandArgument != null)
{
Teams.UpdateTeamStatus(int.Parse(e.CommandArgument.ToString()), "Pending");
}
}
答案 0 :(得分:0)
我不知道为什么DropDownList SelectedIndexChanged不会触发ItemCommand
事件。但你可以这样做:
protected void repeater_ItemCreated(object sender, RepeaterItemEventArgs e)
{
var drlApplicationStatus = (DropDownList)e.Item.FindControl("drlApplicationStatus");
drlApplicationStatus.SelectedIndexChanged += drlApplicationStatus_SelectedIndexChanged;
}
private void drlApplicationStatus_SelectedIndexChanged(object sender, EventArgs e)
{
var drlApplicationStatus = (DropDownList)sender;
Response.Write(drlApplicationStatus.SelectedValue);
Response.Write(drlApplicationStatus.SelectedItem.Text);
}