Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid sort template column

Status
Not open for further replies.

aaronjonmartin

Technical User
Jul 9, 2002
475
GB
Hi guys hope you can shed some light on this. I have a datagrid which contains a template column which displays a firstname and surname from 2 records in a database. Here is the code for the template column:

Code:
<asp:TemplateColumn HeaderText="Name">
 <ItemTemplate>
   <%# DataBinder.Eval(Container.DataItem, "FirstName") %> 
   <%# DataBinder.Eval(Container.DataItem, "Surname") %>
 </ItemTemplate>
</asp:TemplateColumn>

I have other columns which are bound columns and are sortable. My question is, can i make this template column sortable? and how do i do it?

Any help with this would be greatly appreciated.

Aaron



&quot;It's so much easier to suggest solutions when you don't know too much about the problem.&quot;
Malcolm Forbes (1919 - 1990)
 
There is a great article on DataGrid's on 4guysfromrolla.com and I think this part discusses sorting and how to implement it:


--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
I should also add that im using VB and i dont have access to Visual Studio. anyone any ideas?

&quot;It's so much easier to suggest solutions when you don't know too much about the problem.&quot;
Malcolm Forbes (1919 - 1990)
 
Thanks for the link ca8msm unfortunately it doesnt help. That example is using bound columns and i have implemented sorting on the bound columns of my datagrid without any problem. My problem lies with sorting the template column which is displaying data from two databased columns.

&quot;It's so much easier to suggest solutions when you don't know too much about the problem.&quot;
Malcolm Forbes (1919 - 1990)
 
Apologies - I think I glossed over the fact that you had mentioned TemplateColumns.

You may be able to do it by using a DataView and using that to sort your data before giving it to your DataGrid. Have a look at the "Sorting Columns in DataGrid" section at:


--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
thanks again for the link ca8msm thats the closest example ive seen so far but its still only one field from the database whereas mine is a combination of two. Does anyone know if what im asking is possible?

&quot;It's so much easier to suggest solutions when you don't know too much about the problem.&quot;
Malcolm Forbes (1919 - 1990)
 
Wouldn't the easiest solution be to combine the first name and surname in SQL so that it is returned as one field and therefore can be sorted like in the example above?

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
you know what i hadnt thought of that, although im not the best with sql im using a stored procedure, anywhere i can see an example of how i could combine them in the stored procedure?

&quot;It's so much easier to suggest solutions when you don't know too much about the problem.&quot;
Malcolm Forbes (1919 - 1990)
 
Try....
select col1, col2, colname = surname + ', ' + firstname, col....
where...

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top