您的位置:首页 > 其它

DataList的问题 - ItemCommand事件不响应

2007-07-02 08:05 218 查看
以前都没有用过datalist,今天用的时候就发现了一个问题,在这里记录下来!

The itemcommand event for the datalist will not fire if you rebind
the DataList control everytime the page loads. This event will fire if you
use the viewstate information when the page gets loaded. The reason is that
if you do not use the view state information the control gets new set of
data and it may not be the same data that you were working on before when
you selected any items in the DataList.

E.g. In the following scenario the Itemcommand event will not fire because
the datalist is populated with new data.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
SqlDataAdapter1.Fill(DataSet11)
..
DataList1.DataBind()
End Sub

But it will fire in this case because we are using viewstate data.
======================

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
SqlDataAdapter1.Fill(DataSet11)
DataList1.DataBind()
End If
End Sub

Hope this helps.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐