Postback does maintain datagrid sort direction image ?

Discussion in 'ASP .Net' started by rockdale, Jun 8, 2006.

  1. rockdale

    rockdale Guest

    Hi, All:
    I dynamic add an arrow up/down image in OnItemDataBound event for my
    datagrid, it works fine. But I have another textbox which trigger
    postback and doing something, after this event get executed, I lost the

    image but the datagrid maintain the same sort order. Should the
    datagrid remain what it looks like (with the riget arrow up/down image)

    before the postback caused by the textbox?

    I tried to get the datagrid header in the text postback event
    (OnChanged), but I do not know how to get the datagrid header. I do not

    want to rebind the datagrid in the textbox OnChanged event.


    Or should I use other method to show the sort direction image?


    private void dgrid_OnItemDataBound(object sender,
    System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    //Sorting Image
    if(e.Item.ItemType == ListItemType.Header)
    {
    foreach(TableCell tc in e.Item.Cells)
    {
    if(tc.Controls.Count > 0)
    {
    try
    {
    LinkButton lkbSortCol =
    (System.Web.UI.WebControls.LinkButton)tc.Controls[0];

    if(lkbSortCol.CommandArgument.ToString().Equals(dgrid.Attributes["SortExpre­ssion"]))

    {

    System.Web.UI.WebControls.Image imgSort = new
    System.Web.UI.WebControls.Image();

    if(dgrid.Attributes["SortDirection"].Equals("DESC"))
    {

    imgSort.ImageUrl = Server.MapPath("Images/sort_desc.gif");
    }
    else
    {

    imgSort.ImageUrl = Server.MapPath("Images/sort_asc.gif");
    }


    tc.Controls.AddAt(1,
    imgSort);
    }
    }
    catch(Exception ex)
    {
    Trace.Write(ex.Message);
    }
    }//end if tc.controls.count > 0
    }//end for


    } //end item type


    Thanks a lot
    -Rockdale
     
    rockdale, Jun 8, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bruno Ferreira
    Replies:
    0
    Views:
    447
    Bruno Ferreira
    Nov 6, 2003
  2. Keithb
    Replies:
    0
    Views:
    971
    Keithb
    Oct 28, 2006
  3. ASF
    Replies:
    3
    Views:
    2,945
  4. rockdale

    Postback does not maintain sort direction Image?

    rockdale, Jun 8, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    4
    Views:
    394
    rockdale
    Jun 21, 2006
  5. Navin
    Replies:
    1
    Views:
    703
    Ken Schaefer
    Sep 9, 2003
Loading...

Share This Page