如何从动态创建的TemplateFIeld动态创建的下拉列表中获取值 [英] How to get the value from dropdown which is dynamically created in dynamically TemplateFIeld
本文介绍了如何从动态创建的TemplateFIeld动态创建的下拉列表中获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有人,
i想要存储动态模板字段中动态创建的下拉值。
所以如何在提交按钮上访问所选下拉值的值。
i以下使用
Dear All,
i want to store the value of dropdown which is dynamically created in dynamically template field.
so how can i access the value of selected dropdown value on the submit button.
i use below
public class AddTemplateToGridView : ITemplate
{
ListItemType _type;
string _colName;
public AddTemplateToGridView(ListItemType type, string colname)
{
_type = type;
_colName = colname;
}
void ITemplate.InstantiateIn(System.Web.UI.Control container)
{
switch (_type)
{
case ListItemType.Item:
DropDownList ht = new DropDownList();
ht.ID = "ht"+_colName;
ht.Width = 50;
ht.Items.Add(new ListItem("Select", "Select"));
ht.Items.Add(new ListItem("P", "P"));
ht.Items.Add(new ListItem("A", "A"));
ht.Items.Add(new ListItem("H", "H"));
ht.Items.Add(new ListItem("S", "S"));
ht.Items.Add(new ListItem("L", "L"));
ht.DataBinding += new EventHandler(ht_DataBinding);
container.Controls.Add(ht);
break;
}
}
}
SO,我怎样才能获得价值提交按钮或其他活动的下拉菜单。
请帮助我...
谢谢和问候
Mitesh
SO, how can i get the value of dropdown in submit button or another event.
Please Help Me...
Thanks and Regards
Mitesh
推荐答案
最好的方法是通过属性发布DropDownList(或者只是SelectedValue):
The best way is to publish DropDownList (or just SelectedValue) through a property:
public class AddTemplateToGridView : ITemplate
{
ListItemType _type;
string _colName;
DropDownList _ht;
// publish DropDownList:
public DropDownList InnerDropDown { get { return _ht; } }
// or publish just SelectedValue:
public string SelectedValue { get { return _ht == null ? string.Empty : _ht.SelectedValue; } }
public AddTemplateToGridView(ListItemType type, string colname)
{
_type = type;
_colName = colname;
}
void ITemplate.InstantiateIn(System.Web.UI.Control container)
{
switch (_type)
{
case ListItemType.Item:
_ht = new DropDownList();
_ht.ID = "ht"+_colName;
_ht.Width = 50;
_ht.Items.Add(new ListItem("Select", "Select"));
_ht.Items.Add(new ListItem("P", "P"));
_ht.Items.Add(new ListItem("A", "A"));
_ht.Items.Add(new ListItem("H", "H"));
_ht.Items.Add(new ListItem("S", "S"));
_ht.Items.Add(new ListItem("L", "L"));
_ht.DataBinding += new EventHandler(ht_DataBinding);
container.Controls.Add(_ht);
break;
}
}
}
这篇关于如何从动态创建的TemplateFIeld动态创建的下拉列表中获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文