从下拉列表中获取所选项目的值 [英] get the value of the selected item form a dropdownlist
本文介绍了从下拉列表中获取所选项目的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在下拉列表中实际获取所选项目的值.该下拉列表位于griw视图的项目模板中.
以下代码确实获取了值,但始终是下拉列表中的第一项:
受保护的 void 视图文件(对象发件人,GridViewCommandEventArgs e)
{
如果(例如CommandName == " 跨度>)
{
如果(Page.IsPostBack)
{
int 索引= Convert.ToInt32(e.CommandArgument);
GridViewRow row = gvunclassified.Rows [Index];
DropDownList Offices = row.FindControl(" ) as DropDownList;
字符串 deparmentname =(办公室是 DropDownList)吗? Offices.SelectedValue:空;
}
}
谢谢
解决方案
尝试在gridview中设置autopostback = true
我也遇到了同样的问题.
然后我在页面中放置了一个隐藏字段,并更改了组合框obchnage事件的java脚本中的值
How to we actually get the value of the selected item in a dropdownlist.The dropdownlist is in an item template of a griw view.
The following code does gets the value but its always theh first item in the dropdownlist:
protected void viewfiles(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "savefiles") { if (Page.IsPostBack) { int Index = Convert.ToInt32(e.CommandArgument); GridViewRow row = gvunclassified.Rows[Index]; DropDownList Offices = row.FindControl("DDept") as DropDownList; String deparmentname = (Offices is DropDownList) ? Offices.SelectedValue : null; } }
thanks解决方案Try setting autopostback = true in gridview
I had also same problem.
then i have put a hidden field in the page and change the value in java script of obchnage event of combo box
这篇关于从下拉列表中获取所选项目的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文