在数据绑定后手动将项目插入到DDL中 [英] Manually insert items into DDL after data binding

查看:87
本文介绍了在数据绑定后手动将项目插入到DDL中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个下拉列表,它从SQL Server动态填充数据,我想在数据绑定之后手动在DDL之上插入两个项目。所以,DDL将有这样的数据:



选择分支(手动插入)

ALL(手动插入)

AIR

AMP

ABG

...



我试图通过使用代码如下:

  ddlBranch.Items.Insert(0,选择分支)
ddlBranch.Items(0) .Value = CMM.sExcVal1

ddlBranch.Items.Insert(1,ALL)
ddlBranch.Items(1).Value =ALL

但它出来给我这样的数据:



选择分支手动插入)

ALL(手动插入)

('AIR'分支应该在这里,但它已经走了)

AMP

ABG

...



手动将ALL项目插入DDL后,AIR已经被所有'。我如何保留来自服务器的所有数据,同时我可以手动插入两个项目?

解决方案

它简单得多比你想的所有你需要做的是更改html代码如下:

 < asp:DropDownList ID =dropdownlist1runat =服务器AppendDataBoundItems =true> 
< asp:ListItem>选择分支< / asp:ListItem>
< asp:ListItem> ALL< / asp:ListItem>
< / asp:DropDownList>

重要的是 AppendDataBoundItems =true位,在您手动输入的两个条目之后,追加将从SQL Server中恢复的其余项目(但是您已经这样做)。



希望有所帮助。



Ash(UK)。


I have a dropdownlist, which dynamically populate data from SQL Server and i wanna manually insert two items on top of the DDL after data binding. So, the DDL would has data something like this:

Select Branch (manually insert)
ALL (manually insert)
AIR
AMP
ABG
...

I tried to achieve it by using code below:

ddlBranch.Items.Insert(0, "Select Branch")
ddlBranch.Items(0).Value = CMM.sExcVal1

ddlBranch.Items.Insert(1, "ALL")
ddlBranch.Items(1).Value = "ALL" 

but it comes out giving me the data like this:

Select Branch (manually insert)
ALL (manually insert)
('AIR' branch should be here but it's gone)
AMP
ABG
...

After manually insert the 'ALL' item into the DDL, the 'AIR' is gone which is already replaced by the 'ALL'. How can i remain all the data from server and at the same time i can manually insert two items?

解决方案

It is much simpler than you think. All you need to do is change the html code as below:

<asp:DropDownList ID="dropdownlist1" runat="server" AppendDataBoundItems="true">
        <asp:ListItem>Select Branch</asp:ListItem>
        <asp:ListItem>ALL</asp:ListItem>
        </asp:DropDownList>

The important thing is the AppendDataBoundItems="true" bit, which will append the remaining items that will be brought back from the SQL Server as normal (however you did it) after the two entries you manually typed in.

Hope that helps.

Ash (UK).

这篇关于在数据绑定后手动将项目插入到DDL中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆