DataList的问题 - ItemCommand事件不响应

以前都没有用过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.
posted @ 2007-07-02 08:05  Vincent Yang  阅读(675)  评论(0编辑  收藏  举报