开发者

Maintain Added List Item while binding from datasource

开发者 https://www.devze.com 2022-12-31 05:26 出处:网络
I have a drop down list, and I added some items in it as follows <asp:DropDownList ID=\"ddlInsAuther\" runat=\"server\"

I have a drop down list, and I added some items in it as follows

        <asp:DropDownList ID="ddlInsAuther" runat="server" 
            DataSourceID="ObjectDataSourceInsAuthers" DataTextField="AutherName" 
            DataValueField="AutherID">
        <asp:ListItem Value="-1">No Authers</asp:ListItem>
        </asp:DropDownList>

And in Datasource

        <asp:ObjectDataSource ID="ObjectDataSourceInsAuthers" runat="server" 
            SelectMethod="GetAll" TypeName="MyProject.BusinessLayer.AuthersFactory">
        </asp:ObjectDataSource>

When it loads it clears the list and loads the new items, I don't want to make a custom binder on page load, how can I maintain my added items in the list while binding from datasource?开发者_如何学运维


You can add AppendDataBoundItems="true" to the DropDownList. Be aware though, if you bind multiple times it will keep adding the items over and over. You would get around this by putting the call to DataBind() in a if (!IsPostBak) but I am not sure if you can do this with an ObjectDataSource.

0

精彩评论

暂无评论...
验证码 换一张
取 消