Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Which button clicked?
Message
General information
Forum:
ASP.NET
Category:
Web forms
Miscellaneous
Thread ID:
00858694
Message ID:
00858765
Views:
8
>How do you determine which button was clicked when you have multiple Select type bound columns?


You need to implement the ItemCommand event of the DataGrid and then do something like this:
protected void ItemCommand(object sender, DataGridCommandEventArgs e) 
{
	// *** Button command Names contain Sku value if set
	if (e.CommandName != null && e.CommandName != "" && e.CommandName != "Page") 
	{
		// *** If we clicked on one of the items to buy - redirect to the item page
		string sku = e.CommandName;
		string qty = ((TextBox) e.Item.FindControl("qty")).Text;
		if (sku != null && sku!="") 
		{
			Server.Transfer("Item.aspx?sku=" + sku.Trim() + "&qty=" + qty + "&Action=Add");
			//Response.Redirect("Item.aspx?sku=" + sku.Trim() + "&qty=" + qty + "&Action=Add");
		}
		
	}
}
Note that this event fires for any clicks you make on buttons, page links etc. so it's important that you filter out all the stuff you're not interested in. In the above example I filter out Page requests and nulls before picking up the values.

Notice also that you get a reference to the selected row with the e.Item property. From there you can query individual values of that row by using FindControl and then retrieving the values.

It's very flexible...
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform