如何使用ASP.NET在edititemtemplate中定义的下拉列表中的代码中访问所选值?

时间:2015-09-24 11:26:49

标签: asp.net drop-down-menu

我在Edititemtemplate中有一个DropDownlist。我想从后面的代码中访问所选的值。

我的aspx

<EditItemTemplate>
<asp:DropDownList ID="ddlcountry" runat="server">
<asp:ListItem Text="Select Country" Value="0" disabled selected></asp:ListItem>
<asp:ListItem Text="india" Value="1"></asp:ListItem>
        </asp:DropDownList>
</EditItemTemplate>

我的aspx.cs

 protected void ListView1_ItemUpdating(object sender, ListViewUpdateEventArgs e)
    {
    //I want to access the dropdown value here//
    }

1 个答案:

答案 0 :(得分:0)

protected void ListView1_ItemUpdating(object sender, ListViewUpdateEventArgs e)
{
DropDownList ddlCountries = (ListView.EditItem.FindControl("ddlcountry") as DropDownList);
if(ddlCountries!=null)
 {
string value=ddlCountries.SelectedValue;
}
}