下拉列表默认值 [英] dropdownlist default value
本文介绍了下拉列表默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
早上好
i在gridview.i中有一个下拉列表我将它绑定到我有一些价值的数据库。
当我运行程序时,它显示默认值为--Select--
但是我想看到默认项目已经选好了。
请帮帮我。
谢谢。
解决方案
这是我以前的问题
试着看这里
分配下拉列表文本值 [ ^ ]
您好,
使用以下代码,
< asp:DataGrid
id = DataGrid1 < span class =code-attribute> runat = server
AutoGenerateColumns = 错误
OnItemDataBound = DataGrid1_ItemDataBound >
< 列 >
< asp:BoundColumn DataField = au_fname HeaderText = au_fname / >
<asp:TemplateColumn >
< HeaderTemplate >
< asp:DropDownList
ID = < span class =code-keyword> HeaderDropDown Runat = server
AutoPostBack = True
OnSelectedIndexChanged = DropDown_SelectedIndexChanged < span class =code-keyword> / >
< / HeaderTemplate >
< ItemTemplate >
< asp:DropDownList
ID = ItemDropDown Runat = 服务器
AutoPostBack = True
< span class =code-attribute> OnSelectedIndexChanged = DropDown_SelectedIndexChanged / >
< / ItemTemplate >
< / asp:TemplateColumn >
< /列 >
< / asp:DataGrid >
protected void DataGrid1_ItemDataBound(object sender,DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType) .AlternatingItem ||
e.Item.ItemType == ListItemType.Item)
{
string [] options = {Option1,Option2,Option3};
DropDownList list =(DropDownList)e.Item.FindControl(ItemDropDown);
list.DataSource = options;
list.DataBind();
}
else if(e.Item.ItemType == ListItemType.Header)
{
string [] options = {OptionA,OptionB,OptionC} ;
DropDownList list =(DropDownList)e.Item.FindControl(HeaderDropDown);
list.DataSource = options;
list.DataBind();
}
}
请参阅以下链接
http://odetocode.com/articles/231.aspx [ ^ ]
问候,
Babu.K
在页面加载中使用
if (!isPostBack)
{
// 编写代码或调用函数来绑定你的gridview
}
感谢
good morning
i have a dropdown in gridview.i am binding it to the database in which i am having some values.
when i run the program, it is showing the default value as --Select--
but i want to see the default item which is already selected.
please help me.
thank you.
解决方案
it''s my previous problem
try to look here
assign dropdownlist text value[^]
Hi,
Use the below code,
<asp:DataGrid id="DataGrid1" runat="server" AutoGenerateColumns="False" OnItemDataBound="DataGrid1_ItemDataBound"> <Columns> <asp:BoundColumn DataField="au_fname" HeaderText="au_fname" /> <asp:TemplateColumn> <HeaderTemplate> <asp:DropDownList ID="HeaderDropDown" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDown_SelectedIndexChanged" /> </HeaderTemplate> <ItemTemplate> <asp:DropDownList ID="ItemDropDown" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDown_SelectedIndexChanged" /> </ItemTemplate> </asp:TemplateColumn> </Columns> </asp:DataGrid>
protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e) { if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) { string[] options = { "Option1", "Option2", "Option3" }; DropDownList list = (DropDownList)e.Item.FindControl("ItemDropDown"); list.DataSource = options; list.DataBind(); } else if(e.Item.ItemType == ListItemType.Header) { string[] options = { "OptionA", "OptionB", "OptionC" }; DropDownList list = (DropDownList)e.Item.FindControl("HeaderDropDown"); list.DataSource = options; list.DataBind(); } }
Refer the below link
http://odetocode.com/articles/231.aspx[^]
Regards,
Babu.K
in page load use
if(!isPostBack) { //write code or call function for bound your gridview here }
Thanks
这篇关于下拉列表默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文