Quantcast
Channel: John Chapman » Web | John Chapman
Viewing all articles
Browse latest Browse all 10

[ASP.NET] Multiple Command (Select, Delete, etc.) Fields in a GridView

$
0
0

I recently had the requirement to provide multiple select-type commands on an ASP.NET GridView that each resulted in a different action. Using an only provides you with the ability to have a single select, single delete, and single edit command. You cannot have multiples of each. I did, however, discover the . Using the you can assign a command name to each button (which can be a regular button, image button, or link button) and execute the appropriate code accordingly.

In your add an OnRowCommand call:

Add your (you can do this with the WYSIWYG in Visual Studio as well):


	
		
		
		
		...
	

In your code-behind, you simply need to use an “If” or a “Switch” to determine which command to execute:

protected void gvData_RowCommand(object sender, GridViewCommandEventArgs e)
{
	if(e.CommandName == "Select")
	{
		
	}
	else if(e.CommandName == "Email")
	{
		
	}
	else if(e.CommandName == "Print")
	{
		
	}
}

That’s it. It’s rather simple and it helped me, so I wanted to share. Hopefully you find it useful.

Source


Viewing all articles
Browse latest Browse all 10

Trending Articles