Forms Data Controls :: Access Gridview's Sorted Dataview?

Jul 16, 2010

ASP.NET 3.5

I've got a Gridview bound to an objectdatasource. Sorting is enabled in gridview, but objectdatasource isn't doing any sorting. I can pick up the unsorted datatable from the Selected event of the objectdatasource, but I really want the sorted version. Is there any event on the gridview where I can access the sorted dataview it must be using internally?

Why am I asking? We're using paging as well (i.e. truncated data in gridview) and I want to loop through the full sorted dataview to find the primary key value to set selectedindex.

View 4 Replies


Similar Messages:

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

Forms Data Controls :: Sorted Gridview Not Displaying All Rows?

May 18, 2010

I see from google that this is a common problem. I have a SQL server database that contains 26 rows of data. Two columns, the first is PK and an identity column (keys numbered 1 to 26) and the second column is a text field (nchar(10)) containing a letter of the alphabet (A..Z). The letters were inserted randomly to simulate sql being unsorted by default. I have a query that returns all of the data ordered by the letter column ascending. If I execute the query in sql server I get 26 rows orderd A..Z.

I have a gridview that is set up for paging (page size = 15) and sorting. When sorting is disabled, all data is correctly displayed on the gridview, 15 rows on the first page, 11 rows on the second page.

If I enable sorting, I get 15 rows on the first page and 11 rows on the second page, however on closer examination I find two letters missing and two letters duplicated on both pages. If I navigate to page two, then back to page 1 I find that the data is then shown correctly and the missing letters are back.

Has anyone struck this issue? I am thinking that the sort is not being initialized correctly, but am not sure where to look.

View 2 Replies

Forms Data Controls :: GridView Not Displaying Sorted Output?

Mar 1, 2010

I am building a SortedList object for use as the DataSource of a GridView control. The key-value pairs are being built manually with the "key" fields being inserted in already sorted order. The "key" column is invisible with the "value" column the single displayed data item. I set the DataSource property of the gridview to the sortedlist and call the Bind method. The gridview then displays the data in random fashion!

View 4 Replies

Forms Data Controls :: Export Sorted Gridview To Excel?

Jan 26, 2011

So I have a gridview that is sortable. I also have enabled it to export to excel. The problem is that it exports the original datasource and not the sorted data on the screen. What I need is when the export control is fired, the exact gridview or newly sorted gridview is sent to an Excel spreadsheet. Here what my excel export looks like:

[Code]....

View 4 Replies

Forms Data Controls :: Gridview Images Do Not Sort When The Columns Are Sorted?

May 21, 2010

I have a gridview which displays images as shown in the code below. When the page loads the images load fine. But when any of the columns are sorted, the images are not displayed. In the page source view the grid still hold reference to the images when they were first loaded.

How do i bind the images so that they sort when the other columns are sorted.

[Code]....

View 4 Replies

Data Controls :: ListBox Items Already Sorted To GridView?

May 7, 2015

Is it possible to have 2 ListBox then when a Button is Click the Items is Sorted already to GridView accordingly. btw I have done a sort button but for LB1 only. and LB2 only.

LB1       LB2          GridView

1           A                1 A

3           B                2 C

2           C                3 B

4           D                4 D

View 1 Replies

DataSource Controls :: Store Sorted GridView Data Into A DataTable

Nov 19, 2010

I have a GridView that sorts and has paging features. I need to grab the data from the SORTED DATA from the GRIDVIEW and put it into a DataTable. Who Do I get that sorted data gridview and store it into a DataTable. I am an ASP.NET Programmer. Goal: Get and Store Sorted GridView Data into a DataTable.

View 2 Replies

Data Controls :: Footer Total Is Incorrect If GridView Is Sorted

Feb 26, 2013

I want to sum of total CountDevice  in footer of template

int total = 0;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)

[Code] ....

I am use sorting on column CountDevice, when sorting this column show double column in footer

For example total countdevice is 100

when sorting on column CountDevice  total show 200

View 1 Replies

Forms Data Controls :: Bind Gridview Using Dataview In The Code Behind?

Jan 26, 2010

How to bind gridview using dataview in the code behind?

View 1 Replies

Forms Data Controls :: Convert A GridView.DataSource To DataTable Or Dataview?

Jul 25, 2010

I have one gridview and i want to take all the values in a datatable or dataview.

I tried like this

DataTable gridTable = (DataTable) dataGrid1.DataSource;

but gridTable is showing null, it should not show null because gridview has lot of records with 3 columns

Is there any way i can convert/store a gridview.Datasource records in a datatable or dataview?

View 16 Replies

Forms Data Controls :: SelectedValue After A Column Has Been Sorted?

Nov 2, 2010

Using ASP.NET 4.0 with C#.

I have a GridView and have sortable columns. When a column is sorted the GridView automatically selects the top row, however the SelectedValue is still representing the row before the column is sorted. The SelectedValue of the GridView only gets changed when a row is selected, but I want that to happen when the GridView is sorted.

For example if I have this in my code:

[Code]....

itemId is populated with the old SelectedValue not the new one after the GridView has been sorted.

View 1 Replies

Forms Data Controls :: When Click The Link Button The Corresponding Colums Will Be Sorted?

Jun 21, 2010

in my application i have to sort the gridview columns. here i set the showheader property of gridview to false.

i have link buttons on the top of the corresponding gridview columns.

here i had bind the DataField to the link button as

<asp:LinkButton ID="lbcontactperson" Text='<%#Bind("contactperson") %>' runat="server">ContactPerson</asp:LinkButton>

my requirement is when i click the link button the corresponding colums will be sorted.

how can we do this.

View 5 Replies

Forms Data Controls :: Sorting In Dataview?

Aug 10, 2010

I want to sort the string which is in the format given below15% Test;15% Sear;40% Santhosh;30% Jeeson;
The output that I am expecting is

40% Santhosh;30% Jeeson;15% Sear;15% Test;

I wrote the following code but it does not work .

string str = "15% Test;15% Sear;40% Santhosh;30% Jeeson;";
Console.WriteLine(str);
DataTable dt = new DataTable("SortBenchMark");
DataRow dr;
dt.Columns.Add("Weightings", typeof(int));
dt.Columns.Add("BenchMark", typeof(string));
string weightings = string.Empty;
string BenchMarkName = string.Empty;
foreach (object o in str.Split(';'))
{
if(o.ToString().Length > 0)
{
dr = dt.NewRow();
dr["Weightings"] = Convert.ToInt32((o.ToString().Split('%'))[0].ToString().Trim());
dr["BenchMark"] = (o.ToString().Split('%'))[1].ToString().Trim();
dt.Rows.Add(dr);
}
}
dt.AcceptChanges();
DataView dataview = new DataView(dt);
dataview.Sort = "Weightings DESC,BenchMark Asc";
string final = string.Empty;
foreach (DataRow drow in dataview.Table.Rows)
{
final += drow["Weightings"].ToString().Trim() + "% " + drow["BenchMark"].ToString().Trim() + ";";
}
Console.WriteLine(final);
Console.ReadLine();

View 2 Replies

Forms Data Controls :: Can A Dataview Be Declared As Public

Mar 29, 2010

Can a dataview be declared as public?

Dim dvEditTreatmentType As DataView = New DataView(dsTreatmentEndDate.Tables(0), "IsNull(DialysisEndDate, '') = ''", "", DataViewRowState.CurrentRows)

can this be declared as public Dataview? is there a way to do it?

View 2 Replies

Forms Data Controls :: What Is The Difference Between Dataview And Datarowview

Mar 15, 2010

What is the difference between dataview and datarowview?

What is the use of datarowview?

View 2 Replies

Forms Data Controls :: Specify Which Columns Are In A DataView From A DataTable?

Mar 24, 2010

HOW TO specify which columns are in a DataView from a DataTable. I want to create a DataView, that only has the columns from a DataTable that I choose, and in the order I want.

Example:
// DataTable_MyTable ~~ Column #0 is for ID. I do not want my view to get this column.
// DataTable_MyTable ~~ Column #1 is for TYPE. I want this column to come in 2nd place in my view.
// DataTable_MyTable ~~ Column #2 is for NAME. I want this column to com in 1st place in my view.

DataView DataView_MyView = new DataView(DataTable_MyTable ~~ some how only get the columns I want, and in the order I want ~~);

// DataView_MyView now has only 2 columns.
// DataView_MyView ~~ Column #0 is NAME.
// DataView_MyView ~~ Column #1 is TYPE.

View 4 Replies

Forms Data Controls :: Exclude A Row From Dataview Sort?

Mar 5, 2010

I have a datatable which contains the summery row as well. I just assign the datasource property of a gridview and call databind method to fill and display the records.

Now, when I applied sorting through dataview to the gridview, the sorting happens along with the summery row, which is a normal behavior. As a result the "Total" - column took place inside the data some times. I want to prevent this.

The best way out for that can be done by creating the summery row at grid view row databound. But unfortunately I could not change the datatable as per this requirement.

Can the dataview sorting exclude the last row of the datatable through any process?..

View 3 Replies

Forms Data Controls :: Determining A Row And Column In A Dataview?

Aug 9, 2010

I know how to do this in a datatable but I would just like to learn how to do it in a dataview.

I have a dataview which is used to populate a gridview. It has the following column

userid Location
123 New York
124 Chicago
125 London

Now, I would like to know how to determine the 124 row and highlight it to a blue in a dataview used to populate a gridview. kindly note, i can do this in a datatable but not a dataview. I would like to learn how to do it in a dataview.

View 6 Replies

Forms Data Controls :: How To Convert DataView To DataSet

Jul 27, 2010

converting a DataView to a DataSet?

I have a DataSet 'programs'. I want to sort if before passing it to a user control where it will be rendered.

I created the DataView and sorted it successfully like so:

[Code]....

The line of code to pass my old (unsorted) dataset to the UC is like this:

[Code]....

What is the syntax for passing the dvPrograms to the UC in a similar manner?

View 16 Replies

Forms Data Controls :: Dataview Control Not Appearing?

Jan 10, 2010

I have the following code in place:

[Code]....

and the following stored procedure:

[Code]....

The Dataview control is not appearing when the page is loaded. Has anyone any ideas ?

View 3 Replies

Forms Data Controls :: Convert DataView Line From VB To C#?

Jan 12, 2010

I have tried the online converters, and none of them that I have tried will accurately convert this. It still tries to add a .Item property to the dataview and that does not exist in c#. I know this is simple...

dv.Item(e.Item.ItemIndex).Row.Item(1)

View 3 Replies

Forms Data Controls :: Export To Excel Using Dataview?

Dec 1, 2010

I'm trying to export a filtered dataview to excel. The code to export works just fine but it exports all the records, not just the ones I filtered on. For example, I have three dropdowns and the dataview seems to work just fine filtering on the dropdown parameters because it shows up correctly in my datagrid on my screen.

This line of code is where I am confused.

[Code]....

View 2 Replies

Forms Data Controls :: Populate FormView From A DataView?

Feb 23, 2010

Im trying to populate my formview from a dataview in the codebehind and the order in which things are happening is causing it to fail.my formview itemtemplate is setup with some eval("fields") which is initially not populated (nothing bound to it) and the page loads ok. i think click on my graph which generates a query and populates a dataview.i then assign that dataview to the formview and run the bind.what happens when i actually run the app is that it says no data is bound to it.i set the debugged to stop at the point where my DV is assigned to my FV and the FV shows a data item count of 1 (as expected) if i keep stepping it puts me in to the eval statements on the aspx page says the data isnt bound.
the error i get is

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

[Code]....

View 2 Replies

Forms Data Controls :: Displaying Date In Sorted Order In "DD-MM-YYYY" FORMAT

Mar 8, 2010

I am having a DOB field in database of type Datetime.I am retrieving this into a gridview .I want to display only date into the gridview in 'DD-MM-YYYY' format and that to in sorting order. How can I do that. I know that by converting DOB to varchar and using SQL Date formats codes(103,105...) I can do that but I can't able to display in sorted order as it will check only the date part and sort the dates. It will not chk the month & year. And I also want the user to insert the date in 'DD-MM-YYYY' format and this to be stored in database. How can I do this? Pls respond me ASAP.

View 6 Replies







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