一个动作触发多个事件
protected void GridView1_RowCommand(object sender,GridViewCommandEventArgs e)
{
if (e.CommandName == "select ")
{
}
}
我想在IF为真的时候可以执行
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
Label3.Text = GridView1.SelectedDataKey.Value.ToString();
}
里面的内容,或更多其他的事件。
------解决方案--------------------直接调用方法就行了
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
------解决方案--------------------直接把
Label3.Text = GridView1.SelectedDataKey.Value.ToString();
写到if中就可以了。
有时候写编程不能钻牛角尖
------解决方案--------------------事件与事件处理代码不要混淆
否则会造成逻辑混乱
------解决方案--------------------using System;
namespace ConsoleApplication1
{
public delegate void MyDelegate();
public interface I
{
event MyDelegate MyEvent;
void FireAway();
}
public class MyClass:I
{
public event MyDelegate MyEvent;
public void FireAway()
{
if(MyEvent!=null)
MyEvent();
else
Console.WriteLine( "MyEvent failed! ");
}
}
public class MainClass
{
static private void f()
{
Console.WriteLine( "F is called ..................... ");
return;
}
static private void fl()
{
Console.WriteLine( "FL is called ..................... ");
Console.ReadLine();
return;
}
static public void Main()
{
/*
* 可以使用接口定义!
I iMy;
iMy=new MyClass();
iMy.FireAway();
iMy.MyEvent +=new MyDelegate(f);
iMy.MyEvent +=new MyDelegate(fl);
iMy.FireAway();
*/
MyClass i=new MyClass();
i.FireAway();
i.MyEvent +=new MyDelegate(f);
i.MyEvent +=new MyDelegate(fl);
i.FireAway();
}
}
}
------解决方案--------------------protected void GridView1_RowCommand(object sender,GridViewCommandEventArgs e)
{
if (e.CommandName == "select ")
{
showlabel();
}
}
我想在IF为真的时候可以执行
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
showlabel();
}
private void showlabel()
{
Label3.Text = GridView1.SelectedDataKey.Value.ToString();
}
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码)
最新版本:20070212
http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html