2012-09-10 30 views
0

我已经创建了一个动态下拉列表并获得了一些数据。这是在ascx.cs页面完成的,并且下拉列表已重新载入?

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

当选择Id时索引更改事件将被触发,并将发送到它的下拉值。然后我想在会话中捕获这个值。

但是,当我选择一个Id然后选择值被加载到下拉列表中出现。

实际的想法是当我选择值3或6或其他任何基于选择的数据需要出现。

在此先感谢。

+0

您是否正在绑定Page_Load事件中的下拉列表? –

回答

2

只有在用户第一次请求页面时,您才需要绑定DropDownList。 检查用户未发布回页Load

if(!IsPostBack) 
{ 
    //Bind your list here 
} 
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 
     } 
}