473,890 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GridView returning null datasource in sort event

I have a gridview where the datasource is bound after a selection. The
result of doing this is that sorting and paging do not work. I was given a
sample of how to resolve this, however my attempt to explicity enable
sorting failes because, unlike the sample, my sort event has a null in the
datasource and I am unsure why this is so.

Sample HTML code is:

<asp:GridView ID="GridView1" runat="server" AutoGenerateCol umns="False"
BackColor="Whit e"
BorderColor="#9 99999" BorderStyle="No ne" BorderWidth="1p x"
GridLines="Vert ical" AllowPaging="Tr ue" AllowSorting="t rue"
PagerSettings-Position="Botto m" PagerStyle-HorizontalAlign ="Left"
OnPageIndexChan ging="GridView1 _PageIndexChang ing"
OnSorting="Grid View1_Sorting">
<FooterStyle BackColor="#CCC CCC" ForeColor="Blac k" />
<asp:BoundFie ld DataField="Job Name" HeaderText="Job Name"
ReadOnly="True" SortExpression= "Job Name" />
<asp:BoundFie ld DataField="Agen cy Number" HeaderText="Age ncy Number"
ReadOnly="True" SortExpression= "Agency Number" />
<asp:BoundFie ld DataField="Trac king Number" HeaderText="Tra cking
Number" ReadOnly="True" SortExpression= "Tracking Number" />
<asp:BoundFie ld DataField="Mail ing Date" HeaderText="Mai ling Date"
HtmlEncode="Fal se" ReadOnly="True" SortExpression= "Mailing Date"
DataFormatStrin g="{0:MM/dd/yyyy}" />
<RowStyle BackColor="#EEE EEE" ForeColor="Blac k" />
<SelectedRowSty le BackColor="#008 A8C" Font-Bold="True" ForeColor="Whit e"
<PagerStyle BackColor="#999 999" ForeColor="Blac k"
HorizontalAlign ="Center" />
<HeaderStyle BackColor="#000 084" Font-Bold="True" ForeColor="Whit e" />
<AlternatingRow Style BackColor="Gain sboro" />

The code-behind sort event is:

protected void GridView1_Sorti ng(object sender, GridViewSortEve ntArgs e)
DataTable dataTable = GridView1.DataS ource as DataTable; <<<<<<<<<< THIS
if (dataTable != null)
int pidx = GridView1.PageI ndex;
string sortDirection = GetSortDirectio n();
DataView dataView = new DataView(dataTa ble);
dataView.Sort = e.SortExpressio n + " " + sortDirection;
GridView1.DataS ource = dataView;
GridView1.DataB ind();
GridView1.PageI ndex = pidx;

The datasource binding occurs after a button click as follows:

protected void SearchTable_Cli ck(object sender, ImageClickEvent Args e)
string conn =
ConfigurationMa nager.Connectio nStrings["TST"].ConnectionStri ng;
TSTBLL bll = new TSTBLL();
TSTMLBE mt = bll.SubmitQuery (tbJobName.Text , tbAgencyNumber. Text,
tbOrderDateFrom .Text, tbOrderDateTo.T ext, conn);
GridView1.DataS ource = mt.Tst_Table;
GridView1.DataB ind();
May 15 '06 #1
3 6954
i would try not to instantane a new object where you say it is null,
this is wiping out the data and assinging a new object. perhaps, not
sure of further details though.

May 16 '06 #2
Actually, I was trying to manipulate the datasource that was created with
the filter request. I finally had to resort to sticking the entire dataset
into a session object and use that for sorting and paging.

"rjl" <rj****@hotmail .com> wrote in message
news:11******** *************@j 55g2000cwa.goog legroups.com...
i would try not to instantane a new object where you say it is null,
this is wiping out the data and assinging a new object. perhaps, not
sure of further details though.

May 16 '06 #3
that is what MSFT would do. I dont like that though, I jsut as soon
read data again.

May 16 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Dick | last post by:
I have a GridView bound to an ObjectDataSource. I have a Button that calls GridView.DataBind. I want the row that is selected before the DataBind to still be selected afterwards. This happens automatically if the data doesn't change. But if records have been added or deleted then it looks as if some code is necessary: I've done this by using GridView.SelectedValue to get the key value of the currently selected Row and then by itterating...
by: jmdolinger | last post by:
Hi all, I'm a newbie to Atlas (and recently ASP.NET) after coming from a long Java background, also have done quite a bit with an Ajax.NET/ASP.NET 1.1 project, but it was basically all javascript, nothing really having to do with ASP.NET... I'm attempting to put together an application that consists of several GridView controls each bound to some xml data. Each table exists in its own update panel. The two effects I'm going for are:
by: jobs | last post by:
I have a gridview that is refreshes when a dropdown is selected outside of it. Sorting is enabled on the gridview but not working. I read that I should set EnableSortingandPagingCallback to true to fix the error: The GridView 'GridView1' fired event Sorting which wasn't handled However, I am now getting:
by: kurt sune | last post by:
I have a an aspx page with a gridview. The gridview is data bound to a generic list of custom classes. The gridview's DataSource is thus not set. Now I want to add sorting to it. So I create an eventhandler thus: Protected Sub grdResult_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles grdResult.Sorting
by: Cindy Lee | last post by:
When I do a sorta on 1 table, then the other table goes back to the original order. What can I set so, it keeps the order of the other current gridview's order. I set all the gridview values in my 'onpageload' in the cs file.
by: =?Utf-8?B?YmJkb2J1ZGR5?= | last post by:
I have a question that maybe somebody can help me out. I have a gridview that is bound to a sqltable, and I have created two template columns. I am having problems getting the sorting to work. I turned on the Allow Sorting property but when I click one of the columns that is bound, it will not sort. Below is the code I am using
by: sharonrao123 | last post by:
hello all, I have a parent gridview company and in this one a nested gridview people, Is it possible to allow the user to select one row or multiple rows from the people gridview using a check box and also get the datakey (in my case personid) of the the rows selected. Please point me in the right direction. This is what i have so far but i have problem accessing the child gridview in the button click event Cheers, Shilpa. <asp:GridView...
by: =?Utf-8?B?QVZM?= | last post by:
Hi I want to implment cusotm sorting in gridview... Ive a dropdown box on my page where ive all the fields(columsn) to be sorted.. whenever hte user selects the value in the dropdown , the gridview should be sorted... As of now, whenever user selects a value in the dropdown , Im rebinding the grid with sorting applied.... but this is hittng the page performance...
by: Peter | last post by:
I have a GridView which is populated by List<ofObjects> Does anyone have example of how to sort the columns of this GridView? I have found examples without DataSourceControl but these use DataTable, I am using List of Objects. Here's one example: http://ryanolshan.com/technology/gridview-without-datasourcecontrol-datasource/
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.