Can I create one event handler for all DataGrid controls in my web application?
I wanna execute same functionality for all DataGrid
controls in my application for example.. inserted event handler. but without calling it manually. I 开发者_运维知识库mean to be called automatically.
Is there anyway to do that ?
Derive from DataGrid and use that class all around your app. Handle the event(s) in the derived class.
Well why not? Just create a Event handler method and then pass it to each GridView's events like this.
//Example for Click Event
GridView1.Click += new EventHandler(mygeneric_Clickhandler)
GridView2.Click += new EventHandler(mygeneric_Clickhandler)
GridView3.Click += new EventHandler(mygeneric_Clickhandler)
protected void mygeneric_Clickhandler(object sender, EventArgs e)
{
your implementation
}
OR you can declaratively do it via markup:
<asp:GridView ID="GridView1" runat="server"
click="mygeneric_Clickhandler"></asp:GridView>
<asp:GridView ID="GridView2" runat="server"
click="mygeneric_Clickhandler"></asp:GridView>
精彩评论