patgarvey
asked on
C# Datagrid can't get sort command and item command to both work
I built a datagrid "TireDisplay", and I added this cool two-way sorting function:
void TireDisplayGrid_SortComman
{
string sortDir = "";
if (Request.QueryString["sort
{
// The sort expression matches what was sorted on last time
if (Request.QueryString["sort
{
sortDir = "ASC";
}
else if (Request.QueryString["sort
{
sortDir = "DESC";
}
else if (Request.QueryString["sort
{
sortDir = "ASC";
}
}
else
{
// Have a new sort expression so always start out ASC
sortDir = "ASC";
}
// Redirect back to this page with the appropriate sort expression and direction.
Response.Redirect(Request.
}
Everything works great. Next, I needed a detail link for items in the grid. So I added an event handler for a button column:
void GetQuote_ItemCommand(Objec
{
//get values from row where button is clicked, create a session variable, and go to detail page
string SelectedPrice = e.Item.Cells[5].Text;
Session["QuotePrice"] = SelectedPrice;
Response.Redirect("PriceQu
}
Everthing still works. Then I added the button column:
<asp:ButtonColumn Text="Get a Quote" ButtonType="LinkButton" Visible="true"/>
Still OK! But the final piece is the "OnItemCommand = GetQuote_ItemCommand" attribute of the grid. As soon as I add this, the sort command breaks. It now tries to activate the GetQuote_ItemCommand event, and the app breaks.
It seems like it can't distinguish between DataGridCommandEventArgs and DataGridSortCommandEventAr
Help!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That worked!! Thanks tushar!!