如何使用ASP.NET从edititemtemplate中定义的“代码隐藏”下拉列表中访问选定值?
我在Edititemtemplate中有一个DropDownlist。我想从代码隐藏中访问选定的值 我的aspx如何使用ASP.NET从edititemtemplate中定义的“代码隐藏”下拉列表中访问选定值?,asp.net,drop-down-menu,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 Tex
<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>
尝试
stringcountry=((DropDownList)e.Item.FindControl(“ddlcountry”))。SelectedValue代码>@Suprabhat:它不起作用,还有其他方法吗?关键字“Item”不起作用work@Suprabhat:是的,'item'不支持,它显示错误:它不工作,还有其他方法吗?关键字'item'不工作,谢谢你的回复,现在我可以得到值。但是我想要文本,即国家name@hakkeem,使用选定值的选定项。
protected void ListView1_ItemUpdating(object sender, ListViewUpdateEventArgs e)
{
//I want to access the dropdown value here//
}
protected void ListView1_ItemUpdating(object sender, ListViewUpdateEventArgs e)
{
DropDownList ddlCountries = (ListView.EditItem.FindControl("ddlcountry") as DropDownList);
if(ddlCountries!=null)
{
string value=ddlCountries.SelectedValue;
}
}