0

我创建了一个动态下拉列表并将一些数据放入其中。这是在 ascx.cs 页面中完成的,并且

当我们在asp.net,c#中选择下拉列表时。我一直在重新加载页面并跳过这些值。例如:我有一个下拉菜单,其中包含以下值:下拉菜单 - Id's (-- Select --,1,2,3,4,5,6,7,8,9)

When Id is selected the Index Changed event would be fired and the dropdown value I would be sending into it. 然后我想在会话中捕获该值。

但是,当我选择一个 Id 时, -- Select -- 值会被加载到下拉列表中以显示。

实际的想法是,当我根据选择选择值 3 或 6 或任何其他值时,需要显示数据。

提前致谢。

4

2 回答 2

2

DropDownList您只需要在用户第一次请求页面时绑定 a 。在页面上绑定之前检查用户是否没有回帖Load

if(!IsPostBack)
{
    //Bind your list here
}
于 2012-09-10T05:16:16.497 回答
0

如果您在页面加载事件中绑定下拉列表而不是将该代码置于非 IsPostBack 条件

Page.IsPostBack Is used to check if the user posted back to the page. Meaning they 
clicked a button or changed a field in the form that causes it to post back to itself.

所以,代码是

Page_Load Event
{
      If(!IsPostBack)
      {
            //bind dropdownlist
      }
}
于 2012-09-10T05:22:41.917 回答