Sorting GridView By Row Number In C# ?

Sep 18, 2010

I have a GridView with a row number (Container.DataItemIndex) column in ASP.NET (1,2,3,4, ...)
I added it in GridView by following code :

<asp:TemplateField HeaderText="#" SortExpression="#">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>

I wanna sort the GridView by this column. I mean

ASC : 1,2,3,4, ...
DESC : n,n-1, ... , 4,3,2,1

How can I do it ?

Edit: I did it by this way [URL] but it sorts # column like 1,11,12,13,...,2,21,22,...
I want to sort # column 1,2,3,...,11,12,13,...

View 3 Replies


Similar Messages:

Forms Data Controls :: Edit / Delete / Sorting / Page Number In Gridview?

Jan 9, 2010

im not sure why but my gridview seems to have stopped working in all areas of Editing, Deleting, Sortinging and i cant click the page number to switch between pages.Ive looked up numerous tutorials and on forums and still cant seem to find a solution that works for me. I have the edit delete sorting and paging check boxes selected.

When i click on any of the links nothing happens. not even a refresh.

<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="NumofPosts"

DataSourceID="SqlDataSource1" [code]......

View 6 Replies

Forms Data Controls :: Getting The Custom Sorting And Paging With Images To Indicate The Sorting Direction In Gridview

Jul 18, 2010

Moderators Note: THIS ISSUE IS BIG FOR ME AND EVEN IF POSSIBLE, GET THE REPLY FROM THE DESIGNER OF GRIDVIEW. I have been looking for him for long. I am really fed up with reviewing a good lot of web pages on how we can possibly customize the gridview to enable sorting and paging. So many sites have listed out a lot of information and so many guidances. But the problem is that one works out fine and the other is a burden. I really feel bad about being given the job of customizing this kind of a gridview which has no user friendly approach to it. Also, this control is rendered without the pager links inside the <tfoot> tag. I have tried the Pear Pager in php. It is that good and easy to use and compared to that, the gridview in asp.net is the worst ever control i have ever tried so far.

1. i can use the images to indicate the sorting direction
2. I can have the custom pager like

[code]

<<Previous 1 2 3 .. 7 Next >>.

[/code]

When i click the next when i am viewing the page at 3 , the pager links should change as

[code]

<<Previous 2 3 4 .. 7 Next >>

[/code]

Kindly look into this type of requirement and firstly tell me whether this is possible with the gridview control. I would like this request even to be escalated to the designers of the gridview control also, so that Microsoft comes out with a reply THAT WORKS and not the kind of stuff like surfing through a lot of links and pages and finally wasting a lot of days precious time and still breaking the head with this useless control. I have spent a lot of time in searching for a perfect way. Not writing a code that is non-standard. I am really serious b'cos I have spent weeks in customizing this control. If I dont get a solid reply atleast now, I am going to generate all the output by HTML content by custom coding.

View 7 Replies

Forms Data Controls :: Gridview Sorting Failed If Multiple Gridview Are Created

Mar 10, 2011

I got a web page, it has a tabcontainer, within each tab, there will be a gridview, all the tabs and gridview are created at run-time, i have only one code, that I will loop through to create all those tabs and gridview. When I apply the sorting, and I click on the column name on any grid, it returned an error saying index was out of bound. BUT, when there is only ONE grid view created, it is working fine, I suspect it mixed up all the grid view's id and so on. But I have assigned different ID to gridview

View 8 Replies

Forms Data Controls :: Sorting A Gridview Using Linkbuttons Situated Outside The Gridview?

Jan 14, 2010

I'd like to sort a gridview using linkbuttons situated outside the gridview. For instance :

[code]....

View 3 Replies

Forms Data Controls :: Gridview Inside Another Gridview Both Sorting - Using 3.5 Visual Studio 2008 C# Code Behind

Apr 16, 2010

I have the gridview inside another gridview, i want to sort that both gridviews, I don't know how to achieve using asp.net 3.5 visual studio 2008 c# code behind. Following are my aspx page,

<div
id="divclm"
runat="server">
<asp:GridView
ID="claimgrid"
runat="server"
AutoGenerateColumns="False" AllowSorting="True"
Width="100%"
AllowPaging="True"
CssClass="gareahead"
EmptyDataText="No Records To Display"
OnRowDataBound="claimgrid_RowDataBound"
OnRowCreated="claimgrid_RowCreated"
GridLines="Both"
OnPageIndexChanging="claimgrid_PageIndexChanging"
OnSorting="claimgrid_Sorting"
CaptionAlign="Right">
<Columns>
<asp:HyperLinkField
Text="<img id='upimg' src='Styles/Images/appschg.gif'/>"
ItemStyle-Width="10px">
<ItemStyle
Width="10px"
/>
</asp:HyperLinkField>
<asp:BoundField
DataField="name"
HeaderText="Name"
SortExpression="name">
<HeaderStyle
HorizontalAlign="Center"
/>
<ItemStyle
HorizontalAlign="Left"
/>
</asp:BoundField>
<asp:BoundField
DataField="code"
HeaderText="Code"
SortExpression="code">
<HeaderStyle
HorizontalAlign="Center"
/>
<ItemStyle
HorizontalAlign="Left"
/>
</asp:BoundField>
<asp:TemplateField>
<ItemTemplate>
</td></tr>
<tr>
<td
colspan="6"><div
id="<%#Eval("code") %>"
style="display:none;position:relative">
<asp:GridView
ID="Gdclmline1"
runat="server"
AllowPaging="True"
AllowSorting="True"
AutoGenerateColumns="False"
OnSorting="Gdclmline1_Sorting" BorderColor="Green"
BorderStyle="Solid"
BorderWidth="1px"
OnRowDataBound="Gdclmline1_RowDataBound"
OnRowEditing="Gdclmline1_RowEditing" Font-Names="Verdana"
Font-Size="8pt"
Font-Strikeout="False"
OnSelectedIndexChanging="Gdclmline1_SelectedIndexChanging"
OnRowUpdating="Gdclmline1_RowUpdating" PageSize="1000"
RowStyle-Wrap="false"
Width="100%"
CssClass="gareahead"
EmptyDataText="No Records To Display"
GridLines="Both">
<PagerSettings
Mode="NextPreviousFirstLast"
NextPageText="Next"
Position="Top"
PreviousPageText="Prev"
/>
<Columns>
<asp:TemplateField
HeaderText="phone"
SortExpression="phone">
<HeaderStyle
HorizontalAlign="Center"
/>
<ItemStyle
HorizontalAlign="Left"
/>
<ItemTemplate>
<asp:Label
ID="lblphone"
runat="server"
Text='<%#Bind("phone") %>'> </asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField
HeaderText="address1"
SortExpression="address2">
<HeaderStyle
HorizontalAlign="Center"
/>
<ItemStyle
HorizontalAlign="Left"
/>
<ItemTemplate>
<asp:Label
ID="lbladdress1
runat="server"
Text='<%#Bind("address1") %>'> </asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle
CssClass="gr"
Height="100px"
HorizontalAlign="Left"
Wrap="true"/>
<SelectedRowStyle
CssClass="gr"
/> <PagerStyle
CssClass="gareahead"
HorizontalAlign="Left"
Wrap="False"
/> <HeaderStyle
CssClass="ghead"
ForeColor="White"
Wrap="true"
/> </asp:GridView>
</div>
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerSettings
Mode="NextPreviousFirstLast"
NextPageText="Next"
Position="Top"
PreviousPageText="Prev"
/>
<HeaderStyle
HorizontalAlign="Center"
VerticalAlign="Middle"
CssClass="ghead"
ForeColor="White"
/>
<RowStyle
CssClass="gr"
/>
<SelectedRowStyle
CssClass="gs"
/>
</asp:GridView>
</div>

that aspx page contains gridview that contain one more gridview inside in it.Now i want to sort out both the grid i.e)claimgrid and Gdclmline1 i want code in c#.

View 3 Replies

Forms Data Controls :: GridView Sorting, Paging And DataBinding / When Control Causes A Postback GridView Is No Longer Sorted?

Jan 10, 2011

I'm trying to extend the GridView control to enable sorting and paging for any situation.

When using my control I am fetching data from a database and filling a DataSet with it, then binding the GridView upon every page load. My first question would be, is this the correct approach?

To sort the GridView I am overriding the OnSorting method which stores the sort expression and direction in the ViewState, then creates a DataView and utalises the Sort method to sort the underlying data. It then sets the Data Source to this DataView and rebinds the GridView.

Paging is handled by OnPageIndexChanging which simply sets the PageIndex property and again rebinds the GridView.

My problem is; when any control causes a postback my GridView is no longer sorted, presumably because it is persistently rebound. If I don't rebind it then the GridView is empty on postback since the data isn't automatically stored in the ViewState. I have considered saving the data source in the ViewState but I would assume that this is bad practice for large amounts of data? - also DataViews are not seralisable.

The only solution I can think of currently is to override OnDataBound and sort the data every time. This results in a double sort when paging triggers a postback which seems inefficient. Code illustration of this below,

[Code]....

I'm looking for the cleanest 'best practice' solution as this is a learning exercise more than anything else.

View 12 Replies

C# - Dot Net Gridview Sorting?

Jun 30, 2010

I have a web application (with C#). I have a GridView and want to be able to sort its contents. I have added the tags

AllowSorting="True"
onsorting="MyGridView_Sorting">
asp:BoundField DataField="NAME" HeaderText="Name" SortExpression="NAME"

inside the GridView. I have implemented the MyGridView_Sorting method. Thing is: it does not work. Does nothing. The header text "Name" looks like an active link, but clicking produces no effect. Putting a break point inside MyGridView_Sorting shows that it actually never goes inside the function. What is wrong? What do I miss?

[Code]....

View 1 Replies

C# - Allow Sorting Of A Gridview?

Mar 18, 2011

I have a gridview and I allowed sorting. But when I run my application I click on the first column to sort it. But I get this error: "The GridView 'gvOutlookMeldingen' fired event Sorting which wasn't handled."

This is the gridview:

<asp:GridView ID="gvOutlookMeldingen" runat="server"
AllowSorting="True" AutoGenerateColumns="False"
AutoGenerateSelectButton="True" onselectedindexchanged="GridView_SelectedIndexChanged">
<Columns>
<asp:TemplateField HeaderText="Melder" ItemStyle-HorizontalAlign="Center" SortExpression="Melder">
<HeaderStyle BorderColor="#1A3491" Width="130px"></HeaderStyle>
<ItemStyle Height="20px" HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<%# (string)Eval("Melder") %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Onderwerp" HeaderText="Onderwerp" />
<asp:TemplateField HeaderText="Omschrijving">
<ItemTemplate>
<div style="overflow:auto; width: 500px; height: 200px;">
<asp:Label ID="lblOmschrijving" runat="server" Text='<%# Bind("Omschrijving")%>'></asp:Label>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Meldingsdatum" HeaderText="Meldingsdatum" />
<asp:BoundField DataField="OutlookID" HeaderText="OutlookID" />
</Columns>
</asp:GridView>

View 3 Replies

Asp.net - Sorting In GridView ?

Feb 2, 2011

since yround 8 hours I search the whole web for simple sorting in gridViews.I tried around 20 HowTos and Examples but it doesn't work.here is my code

[code]...

View 1 Replies

Name Or Number Search In Textbox While Entering The First Letter Or Number Charactor Or Number?

Feb 2, 2010

I am using the asp.net and framework 2.0 with Ajax enable web.i have a text box and when user will enter "a" or number in this will search the name started from "a" character or number if he or she enter the number basically we can say live-search.

Employee search: Textbox.In this text box she/he will enter the first character of name or first number of employeeno and according to the a character name will search in list.

View 1 Replies

GridView Sorting Without JavaScript?

Mar 15, 2010

When "AllowSorting" is true on an asp.net GridView, it just makes the headers with a SortExpression clickable. Trouble is that it does this with JavaScript links - so with JS turned off you cannot sort the columns. Before I go and write my own HeaderTemplate to use Querystrings instead of JavaScript, am I missing an easier way of being able to sort a GridView without any relyance upon JavaScript?

View 1 Replies

Manual Sorting For Gridview In Vb.net?

Feb 25, 2011

I have done research on how to manually create sorting in a grid-view and none of it is thorough enough for me to follow. I need more of a step by step solution, like what event should my sorting code go in, how would i enable the headers to allow sorting. normally, i just have .net do this but for some reason this time it doesn't allow it, maybe because i am not using a datasource.

that's my code that creates a datable and then binds to the gridview.

Function toptable()
Dim reader As SqlDataReader
cmd.Parameters.AddWithValue("@yeartoget", DropDownList1.SelectedValue)
cmd.Parameters.AddWithValue("@mode", RadioButtonList1.SelectedValue)
<FooterTemplate>
<%#Getmovesales1().ToString("P1")%>.......

View 2 Replies

C# - Sorting GridView Using JQuery

Nov 9, 2010

How can I sort gridview with JQuery using C#?

View 1 Replies

Implement Sorting On GridView?

Jul 27, 2010

Could any one let me know how to implement sorting on GridView?

View 1 Replies

C# - Sorting A Gridview In Class?

Mar 12, 2010

ok i have a project which has many gridview in its pages... now i am sorting the fridveiw using the sorting function like this:

protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dt = Session["TaskTable2"] as DataTable;
if (dt != null)

[Code].....

and i get view state error...

is here a way to put this entire thing in the class... because it is getting repeated everywhere...

View 1 Replies

How To Do Sorting In A Gridview / Cannot Get It To Work

Mar 10, 2012

I have a Gridview thats is working just fine, but when i click the sort header link, nothing happens !?? it will not sort the data by Desc or Asc

Main grid_view code

Code:
<asp:GridView ID="MySource" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" DataKeyNames="email_id" AllowPaging="True" emptydatatext="Ingen Data tilgngelig." allowsorting="true" EnableViewState="False" OnSorting="MySource_Sorting"
onRowDataBound="myGridView_RowDataBound">

[code]...

View 8 Replies

VS 2010 - Sorting In Gridview

Jun 21, 2012

I am trying to sort in a grid view. There is some error in 7th line from last (Which is underlined) in my code, how to retrieve the data table there.

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myConn As New SqlConnection
myConn.ConnectionString = ConfigurationManager.ConnectionStrings("Fall2010_MSIS5643_Team1ConnectionString").ToString

[code]....

View 2 Replies

Sorting Gridview With Entity Framework?

Oct 15, 2010

I have a method

[code]....

and it's starting to smell, bad. I have 4 columns that I have to sort on. I'd like to avoid doing a switch or something to determine which property on the CustomerSet I'm trying to order. What would a better programmer do to associate the SortExpression, which is a string, to the property on one of my CustomerSet objects?

View 1 Replies

C# - Sorting Gridview Bound To Linq SP

Oct 22, 2010

I have a grid bound to a linqed SP thus:

Session["results"] = db.spGetCaseByNumberOrSurname(txtCaseNum.Text.Trim(), null).ToList();
gvResults.DataSource = Session["results"];

on the sorting of it, i would like to be able to do this..

protected void gvResults_Sorting(object sender, GridViewSortEventArgs e)
{
string sortExpression = e.SortExpression;
List<spGetCaseByNumberOrSurnameResult> data = Session["results"] as List<spGetCaseByNumberOrSurnameResult>;
if (sd == SortDirection.Ascending)
{
sd = SortDirection.Descending;
gvResults.DataSource = data.OrderBy(d => d.GetType().GetProperty(sortExpression));
}
else
{
sd = SortDirection.Ascending;
gvResults.DataSource = data.OrderByDescending(d => d.GetType().GetProperty(sortExpression));
}
gvResults.DataBind();
}

sadly that doesnt do any sorting at all..it in fact errors with "The data source does not support server-side data paging."

View 1 Replies

Web Forms :: Custom Sorting In Gridview

Apr 12, 2010

In grid view we have option by default as sorting and paging. if i disabled those two textboxes by pro grammatically i need to get that feature.

View 2 Replies

Gridview Edit Not Working After Sorting ASP.NET

Jun 4, 2010

I have a Gridview for which I have provided Sorting, Edit functionality. I am not able to perform EDIT when I perform Sorting. After sorting edit is set on some other row.

View 1 Replies

Sorting Data With Gridview And ObjectDataSource?

Feb 2, 2011

how I do a sorting in a gridView with data bound by a ObjectDataSource?

View 2 Replies

Sorting Of A Gridview Using The Tablesorter Plugin?

Oct 20, 2010

I'm trying to add sorting of a gridview using the tablesorter plugin.

However, the gridview does not render the THEAD and TBODY tags. Is there a way to get it to add them?

View 1 Replies

Sorting GridView Formed With Data Set?

Apr 13, 2010

Following Code is for Sorting GridView Formed With DataSet

Source: [URL]

But it is not displaying any output. There is no problem in sql connection. I am unable to trace the error,

public partial class _Default : System.Web.UI.Page
{
private const string ASCENDING = " ASC";
private const string DESCENDING = " DESC";
private DataSet GetData()

[Code]....

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved