Datagrid, add SortExpression dynamically

Discussion in 'ASP .Net' started by fabrice, Dec 6, 2005.

  1. fabrice

    fabrice Guest

    hello
    is there a way for adding "Sort Expression" in a Datagrid from code behind.
    These is my two tests :

    in my .aspx page, the datagrid :
    ------------------------------------

    <asp:DataGrid id="myPs4Grid" runat="server"....
    ...

    <Columns>
    <asp:BoundColumn DataField="coddos" ReadOnly="true">
    <ItemStyle Font-Names="Times New Roman, Times, serif"
    ForeColor="#003B6F" Font-Size="10" horizontalalign="Center"
    VerticalAlign="Middle" width="15%">
    </ItemStyle>
    </asp:BoundColumn>
    .....


    in my code behind :
    ----------------------------


    Sub myPs4Grid_ItemBound(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.DataGridItemEventArgs)

    If e.Item.ItemType = ListItemType.Header Then
    'First Solution

    Dim btn As LinkButton = CType(e.Item.Cells(0).Controls(0), LinkButton)
    btn.text="File"
    btn.Attributes("SortExpression")="file" ----> it does not work


    'Second Solution

    CType(e.Item.Cells(0).Controls(0), LinkButton).Text = "File"
    e.Item.Cells(0).Attributes("SortExpression")="File" ------------------>
    It does not work.

    End Sub


    Thanks for you help
    fabrice
     
    fabrice, Dec 6, 2005
    #1
    1. Advertising

  2. fabrice

    addup Guest

    SortExpression is a property of the DataGridColumn, not the linkbutton.

    Try and set the SortExpression on the Column before your databind

    myPs4Grid.Columns(0).SortExpression = "File"
    myPs4Grid.DataBind()

    -- addup --
     
    addup, Dec 6, 2005
    #2
    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. =?Utf-8?B?UGF1bA==?=

    SortExpression makes SortCommand event not to trig

    =?Utf-8?B?UGF1bA==?=, Sep 22, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    480
    =?Utf-8?B?UGF1bA==?=
    Sep 22, 2005
  2. =?Utf-8?B?UGF1bA==?=

    Setting SortExpression programmatically

    =?Utf-8?B?UGF1bA==?=, Sep 26, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    6,073
    Kalpesh
    Sep 27, 2005
  3. =?Utf-8?B?SmFtZXMgUm9zZXdlbGw=?=

    GridView and SortExpression after Column Removed

    =?Utf-8?B?SmFtZXMgUm9zZXdlbGw=?=, Feb 26, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    3,319
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    Feb 27, 2006
  4. JJ
    Replies:
    3
    Views:
    687
    Mark Rae
    Jun 8, 2007
  5. Datagrid e.SortExpression is wrong

    , Jun 9, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    456
Loading...

Share This Page