asp.net 3.5中的datalist

asp.net 3.5中的datalist

问题描述:

如何在按钮上访问数据列表DataListCommandEventArgs单击

how to access data list DataListCommandEventArgs on button click

所有事件处理程序都有两个参数:

1)An object 名为 sender ,它是发起事件的类实例。例如,在Button.Click处理程序中, sender 将是用户单击的按钮。

2) EventArgs (或派生)类实例,名为 e ,它包含事件参数(如果有)。通常,如果这是派生的EventArgs类,那么事件将被声明为将派生类作为参数而不是标准的默认EventArgs,但是您可以将EventArgs转换为派生类并检查它是否有效:

All event handlers have two parameters:
1) An object called sender which is the class instance which originated the event. For example, in a Button.Click handler, sender would be the button the user clicked.
2) An EventArgs (or derived) class instance called e which holds the event arguments if any. Normally, if this is a derived EventArgs class, then the event will be declared as having the derived class as a parameter instead of the standard default EventArgs, but you can cast the EventArgs to a derived class and check if it is valid:
void mySource_Event(object sender, EventArgs e)
   {
   MyEventArgs args = e as MyEventArgs;
   if (args != null)
      {
      // You can use args here.
      }
   }

在VB中可能是这样的:

In VB is would be something like:

Private Sub mySource_Event(sender As Object, e As EventArgs) Handles ...
    Dim args As MyEventArgs = TryCast(e, MyEventArgs)
    If args IsNot Nothing Then
        ' You can use args here.
    End If
End Sub