Solved

Grid View control + Colum sorting

Posted on 2010-11-30
6
374 Views
Last Modified: 2012-08-13
I have a Grid View control with coming from multiple tables, and i need to sort different columns which are being displaced indirectly  by Grid View control.
Indirectly means,  these columns are included in the "Datamember" of GridView control as foreign keys. and these fields are populated in the Grid View control  via this foreign key.

How to srt this kind of Grid view control--
0
Comment
Question by:Ammar Iqbal
6 Comments
 
LVL 29

Expert Comment

by:Kumaraswamy R
ID: 34238164
0
 
LVL 1

Author Comment

by:Ammar Iqbal
ID: 34238180
i have looked into these links. these are not helpful for my requirment. i have cloumns conatained in my grid view coming from differnet tables. I want to sort in a way all records with respect to that column are sorted.
At the moment If i click on the Header of any column, then  only that column is sorted , not the whole grid view control
0
 
LVL 29

Accepted Solution

by:
anarki_jimbel earned 250 total points
ID: 34242550
I believe you may try to sort your underlying DataTable (which you get as a result of an SQL request, e.g.). Something like:

// Sorting DataTable
DataView dataView = new DataView(dTable);
dataView.Sort = " AutoID DESC, Name DESC";
foreach (DataRowView view in dataView)
{
Response.Write(view["Address"].ToString());
}

See http://www.dotnetfunda.com/articles/article131.aspx for more details
0
 
LVL 7

Assisted Solution

by:kovilpattiBalu
kovilpattiBalu earned 250 total points
ID: 34256188

<asp:datagrid id="dgSam" runat="server" AllowCustomPaging="True" AllowPaging="True" AutoGenerateColumns="False"
      AllowSorting="True" EditAllRequired="True" AddRequired="True" DataKeyField="UserID" onadd="dgSam_Add" onupdate="dgSam_Update" onclear="dgSam_Clear" oncancel="dgSam_Cancel" oneditall="dgSam_EditAll">
      <PagerStyle Position="TopAndBottom"></PagerStyle>
      <EditItemStyle CssClass="HeaderFooter"></EditItemStyle>
      <Columns>
            <xnet:BoundColumn SortBehavior="None" DataField="ID" SortExpression="U.ID ASC" ReadOnly="True"
                  SortDescendingExpression="U.ID DESC" HeaderText="ID"></xnet:BoundColumn>
            <xnet:BoundColumn SortBehavior="None" DataField="CompanyName" SortExpression="C.Name ASC" ReadOnly="True"
                  SortDescendingExpression="C.Name DESC" HeaderText="Company "></xnet:BoundColumn>
            <xnet:BoundColumn SortBehavior="None" DataField="UserName" SortExpression="Us.UName ASC" SortDescendingExpression="Us.UName DESC"
                  HeaderText="Member ID"></xnet:BoundColumn>
            <xnet:BoundColumn SortBehavior="None" DataField="FullName" SortExpression="Us.LName ASC" ReadOnly="True"
                  SortDescendingExpression="Us.LName DESC" HeaderText="Name"></xnet:BoundColumn>
            <xnet:BoundColumn SortBehavior="None" DataField="Email" SortExpression="Us.Email ASC" SortDescendingExpression="Us.Email DESC"
                  HeaderText="Email Address">
                  <ItemStyle Wrap="False"></ItemStyle>
            </xnet:BoundColumn>
            <xnet:BoundColumn SortBehavior="None" DataField="SchemaName" ReadOnly="True" HeaderText="User Type "></xnet:BoundColumn>
            
            
      </Columns>
</asp:datagrid>
0
 
LVL 19

Expert Comment

by:Amandeep Singh Bhullar
ID: 34886507
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question