DropDownList AppendDataBoundItems (first item to b

2019-01-10 22:52发布

I have a DropDownList inside an UpdatePanel that is populated on postback from a SqlDataSource. It has a parameter which is another control. I sometimes need multiple postbacks, but what happens is that each time the update panel refreshes, items are added to the DropDownList. So the DropDownList ends up having data that is incorrect, or repeated data.

I have the AppendDataBoundItems property set to true because I need the first item to be blank.

How can I overcome this problem? Is there another way to have a blank first item?

(This DropDownList is in an asp.net-2.0 web app, and codebehind is in c#)

Thank you.

8条回答
Summer. ? 凉城
2楼-- · 2019-01-10 23:25

Here's an Idea.

There's a property in the drop down list called AutoPostBack set it to true and then in the code behind you put all the binding method inside the if(!Page.IsPostBack). That worked for me.

regards.

查看更多
劳资没心,怎么记你
3楼-- · 2019-01-10 23:27

You probably bind that DropDownList in the code behind. So you should not do it after postback again:

// probably in Page_Load method
if (!Page.IsPostBack)
{
    // do data binding here
};
查看更多
登录 后发表回答