Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Sorting on a DataField (not KeyField)

Reply
Thread Tools

Sorting on a DataField (not KeyField)

 
 
Xarky
Guest
Posts: n/a
 
      04-11-2005
Hi,
I am using a datagrid, with two columns(ID is the keyfield). Now
data in the grid is being sorted by this ID. How can I sort data on
the Name DataField.

<Columns>
<asp:BoundColumn DataField="ID" HeaderText="ID"></asp:BoundColumn>
<asp:BoundColumn DataField="Name" HeaderText="Name"></asp:BoundColumn>
</Columns>


Can someone help me out please.
Thanks in Advance
 
Reply With Quote
 
 
 
 
Elton Wang
Guest
Posts: n/a
 
      04-11-2005
Hi Xarky,

If you are using DataSet or DataTable as data source of
your datagrid, you can sort by Name by following code:

DataView dv = Ds.Tables[0].DefaultView; // or
tbl.DefaultView
dv.Sort = "Name"; // or Desc: dv.Sort = "Name Desc"
Datagrid.DataSource = dv;
Daatagrid.DataBind();

And if you use DataReader as data source, you need change
sql query.

Select * from table_name Order By Name

HTH

Elton Wang



>-----Original Message-----
>Hi,
> I am using a datagrid, with two columns(ID is the

keyfield). Now
>data in the grid is being sorted by this ID. How can I

sort data on
>the Name DataField.
>
><Columns>
><asp:BoundColumn DataField="ID"

HeaderText="ID"></asp:BoundColumn>
><asp:BoundColumn DataField="Name"

HeaderText="Name"></asp:BoundColumn>
></Columns>
>
>
>Can someone help me out please.
>Thanks in Advance
>.
>

 
Reply With Quote
 
 
 
 
xarky d_best
Guest
Posts: n/a
 
      04-12-2005
Hi,
I am using a DataSet. Thanks, that solved my problem.



*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get DataField value of a cell Dinçer ASP .Net 3 12-09-2004 09:10 AM
Get the datafield name?? Husht ASP .Net 0 08-04-2004 03:04 PM
Get the datafield name?? Husht ASP .Net 1 08-04-2004 12:49 PM
get DataField value in UpdateCommand richard ASP .Net 0 12-02-2003 07:35 AM
show just the date in a datagrid column when the datafield is an datetime field Adil Bohoudi ASP .Net 1 08-06-2003 04:07 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57