提供“创造新”下拉列表中的选项。 [英] Providing "create new" option in the dropdownlist.
本文介绍了提供“创造新”下拉列表中的选项。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个asp.net网页:
1.Form.aspx
2.Subform.aspx
- >我有一个下拉列表绑定到sql datasource。当我运行form.aspx时,dropdownlist成功显示数据库中的所有名称。
- > 但我想要的是我的下拉列表还会显示一个创建新选项以及数据库记录。
所以当我从下拉列表中选择创建新时,第二个网页ieSubform.aspx被打开。
I have two asp.net webpages:
1.Form.aspx
2.Subform.aspx
->I have a dropdownlist bound to a sql datasource.when i run the form.aspx,the dropdownlist successfully shows all the names from the database.
->But what i want My dropdownlist to also show an option "create new" along with the database records.
So that when i select "create new" from the dropdownlist, the second webpage i.e.Subform.aspx gets open.
推荐答案
正如你所说的那样,
创建新以及数据库记录。
最简单的方法是
修改查询如下所示
as you said to show,
"create new" along with the database records.
A simplest way is
modify query as below
select 0 as id, 'Create New' as name
union all
select id,name from tblnm
快乐编码!
:)
Happy Coding!
:)
<asp:DropDownList ID="DropDownList1" AppendDataBoundItems="true" runat="server" DataSourceID="SqlDataSource1" DataTextField="state" DataValueField="state">
<asp:ListItem Text="(Select a State)" Value="" />
</asp:DropDownList>
下拉列表项可以通过代码隐藏添加...但是,一个要点是
你不能在页面加载中添加项目。
Ex:ddl_type .Items.Insert(0,Create New);
可以在页面生命周期的Page_PreRenderComplete阶段添加。
这个项目将在页面生命周期的这个阶段受限。
原因:这里的Page_PreRenderComplete()数据源ID将被追加所需的控件。
详细说明请点击此链接。
http://msdn.microsoft.com/en-us/library/ms178472(v = VS.100)的.aspx [ ^ ]
打开新页面启用Autopostbac k = true并且在下拉列表中的代码后面选择了索引更改。
所有最佳
有问候
The Dropdownlist Items can be added through codebehind...But, one main point is
you cant add the items in page load.
Ex: ddl_type.Items.Insert(0,"Create New");
It can be added on Page_PreRenderComplete stage of the Page Life Cycle.
The Items Will Be Bounded in this stage of Page Life Cycle.
Reason: The Page_PreRenderComplete() here the datasource id will be appended to the required controls.
For Detailed Description Go through this link.
http://msdn.microsoft.com/en-us/library/ms178472(v=vs.100).aspx[^]
To Open new page Enable the Autopostback = true and in code behind on dropdownlist selected index change.
All The Best
With Regards
这篇关于提供“创造新”下拉列表中的选项。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文