Datagrid, add SortExpression dynamically

F

fabrice

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
 
A

addup

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 --
 

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,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top