sort expression always = "" in gridview... why?

S

Smokey Grindle

I'm trying desperatly to add a sort order arrow to my grid view and have
this code below ofr it... but when the code runs the girdview sortexpression
is always = "" never the sort name... why?! i want the image to show up on
only the column sorting on...

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
foreach (TableCell tc in e.Row.Cells)
{
if (tc.HasControls())
{
// search for the header link
LinkButton lnk = (LinkButton)tc.Controls[0];
if (lnk != null)
{
// inizialize a new image
System.Web.UI.WebControls.Image img = new
System.Web.UI.WebControls.Image();
// setting the dynamically URL of the image
img.ImageUrl = "~/img/ico_" + (GridView1.SortDirection
== SortDirection.Ascending ? "asc" : "desc") + ".gif";
// checking if the header link is the user's choice
if (GridView1.SortExpression == lnk.CommandArgument)
{
// adding a space and the image to the header link
tc.Controls.Add(new LiteralControl(" "));
tc.Controls.Add(img);
}
}
}
}
}
} every time that executes the sort expression is = "" never the command
argument.....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top