473,287 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

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" AutoGenerateColumns="False"
BackColor="White"
BorderColor="#999999" BorderStyle="None" BorderWidth="1px"
CellPadding="3"
GridLines="Vertical" AllowPaging="True" AllowSorting="true"
PagerSettings-Mode="Numeric"
PagerSettings-Position="Bottom" PagerStyle-HorizontalAlign="Left"
OnPageIndexChanging="GridView1_PageIndexChanging"
OnSorting="GridView1_Sorting">
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<Columns>
<asp:BoundField DataField="Job Name" HeaderText="Job Name"
ReadOnly="True" SortExpression="Job Name" />
<asp:BoundField DataField="Agency Number" HeaderText="Agency Number"
ReadOnly="True" SortExpression="Agency Number" />
<asp:BoundField DataField="Tracking Number" HeaderText="Tracking
Number" ReadOnly="True" SortExpression="Tracking Number" />
<asp:BoundField DataField="Mailing Date" HeaderText="Mailing Date"
HtmlEncode="False" ReadOnly="True" SortExpression="Mailing Date"
DataFormatString="{0:MM/dd/yyyy}" />
</Columns>
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White"
/>
<PagerStyle BackColor="#999999" ForeColor="Black"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="Gainsboro" />
</asp:GridView>

The code-behind sort event is:

protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dataTable = GridView1.DataSource as DataTable; <<<<<<<<<< THIS
IS NULL EVEN THOUGH SET AFTER A SUBMIT QUERY (below)
if (dataTable != null)
{
int pidx = GridView1.PageIndex;
string sortDirection = GetSortDirection();
DataView dataView = new DataView(dataTable);
dataView.Sort = e.SortExpression + " " + sortDirection;
GridView1.DataSource = dataView;
GridView1.DataBind();
GridView1.PageIndex = pidx;
}
}

The datasource binding occurs after a button click as follows:

protected void SearchTable_Click(object sender, ImageClickEventArgs e)
{
string conn =
ConfigurationManager.ConnectionStrings["TST"].ConnectionString;
TSTBLL bll = new TSTBLL();
TSTMLBE mt = bll.SubmitQuery(tbJobName.Text, tbAgencyNumber.Text,
tbOrderDateFrom.Text, tbOrderDateTo.Text, conn);
GridView1.DataSource = mt.Tst_Table;
GridView1.DataBind();
}
May 15 '06 #1
3 6910
rjl
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*********************@j55g2000cwa.googlegro ups.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

5
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...
1
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...
2
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...
4
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...
12
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...
3
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....
0
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...
0
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...
3
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.