473,769 Members | 5,877 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GridView page changing doesn't work (Non SQL Source)

Hello,

I have a GridView that I built to show the files in a directory. The
problem that I am having is that when I click on the second page (2), the
GridView disappears. Also, I can't sort by any of the columns.

Below is the code that I am using. Any help would be appreciated.

Thanks, sck10

<asp:GridView ID="gvSearchLis t" runat="server"
AllowPaging="Tr ue"
AllowSorting="T rue"
AutoGenerateSel ectButton="Fals e"
AutoGenerateCol umns="False"
PageSize="15"
style="width:70 %"
OnPageIndexChan ging="gvSearchL ist_PageIndexCh anging"
OnSorting="gvSe archList_Sortin g"
OnSelectedIndex Changed="gvSear chList_Selected IndexChanged">
<Columns>
<asp:BoundFie ld DataField="Name "
HeaderText="Fil e Name"
SortExpression= "Name"
HeaderStyle-VerticalAlign=" Bottom"
ItemStyle-HorizontalAlign ="left"
ItemStyle-Width="45%" />

<asp:BoundFie ld DataField="Last WriteTime"
HeaderText="Las t Write Time"
SortExpression= "LastWriteT ime"
HeaderStyle-VerticalAlign=" Bottom"
ItemStyle-HorizontalAlign ="left"
ItemStyle-Width="40%" />

<asp:BoundFie ld DataField="Leng th"
HeaderText="Fil e Size"
ReadOnly="True"
SortExpression= "Length"
HeaderStyle-VerticalAlign=" Bottom"
ItemStyle-HorizontalAlign ="center"
ItemStyle-Width="15%" />

</Columns>
</asp:GridView>

protected void Search_Click(ob ject Sender, CommandEventArg s Args)
{
this.DirectoryL ist(this.txtSea rch.Text);
}
protected void DirectoryList(s tring DirectoryPath)
{
DirectoryInfo dirInfo = new DirectoryInfo(S erver.MapPath(s tr00));
this.gvSearchLi st.DataSource = dirInfo.GetFile s("*.*");
this.gvSearchLi st.DataBind();
}
protected void gvSearchList_Se lectedIndexChan ged(object Sender, EventArgs
e)
{

}
private string ConvertSortDire ctionToSql(Sort Direction sortDirection)
{
string newSortDirectio n = String.Empty;

switch (sortDirection)
{
case SortDirection.A scending:
newSortDirectio n = "ASC";
break;

case SortDirection.D escending:
newSortDirectio n = "DESC";
break;
}

return newSortDirectio n;
}
protected void gvSearchList_Pa geIndexChanging (object sender,
GridViewPageEve ntArgs e)
{
gvSearchList.Pa geIndex = e.NewPageIndex;
gvSearchList.Da taBind();
this.gvSearchLi st.Visible = true;
}
protected void gvSearchList_So rting(object sender, GridViewSortEve ntArgs
e)
{
DataTable dataTable = gvSearchList.Da taSource as DataTable;

if (dataTable != null)
{
DataView dataView = new DataView(dataTa ble);
dataView.Sort = e.SortExpressio n + " " +
ConvertSortDire ctionToSql(e.So rtDirection);

gvSearchList.Da taSource = dataView;
gvSearchList.Da taBind();
}
}

Dec 1 '06 #1
2 3874
Hi,

I suggest you create a DataSource (with its DataView) to support pagination
and sorting.

Please take a look at following article:

#Folder Contents DataSource Control - The Code Project - ASP.NET
http://www.codeproject.com/useritems...DataSource.asp
I think it's what you needed. Let me know if it's not the case.
Sincerely,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Dec 4 '06 #2
Thanks Walter.
"Walter Wang [MSFT]" <wa****@online. microsoft.comwr ote in message
news:GI******** ******@TK2MSFTN GHUB02.phx.gbl. ..
Hi,

I suggest you create a DataSource (with its DataView) to support
pagination
and sorting.

Please take a look at following article:

#Folder Contents DataSource Control - The Code Project - ASP.NET
http://www.codeproject.com/useritems...DataSource.asp
I think it's what you needed. Let me know if it's not the case.
Sincerely,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your
reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no
rights.

Dec 5 '06 #3

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

Similar topics

5
4838
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...
1
1657
by: Andrew Nav | last post by:
I dragged a table from a datasource on to my web form and the GridView cpntrol was created. I turned on paging, and Edit and Delete buttons. I ran the app and everything worked great - not a single line of code written yet. Then I wanted to add a simple feature where the user could filter out data based on a value in a single column. I added a little code that set the FilterExpression property of the SqlDataSource, and that seemed...
6
4900
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of the html page controls the form fields that are required. It doesn't function like it's supposed to and I can leave all the fields blank and it still submits the form. Also I can't get it to transfer the file in the upload section. The file name...
0
2417
by: John Smith | last post by:
ASP.Net 2.0 / C# / IIS 6 I have 2 pages. The master page consists of a tabbed menu created using the Menu and MultiView controls. Something like this: http://fredrik.nsquared2.com/viewpost.aspx?PostID=344&showfeedback=true The second page is a user control that contains a GridView control linked to a database table. What's supposed to happen is that the user clicks on a menu choice and an appropriate user control will load. For...
3
2770
by: tarscher | last post by:
Hi all, I have a grid that contains 7 columns from 3 tables (3 unique keys, 4 normal fields). I show this 7 columns on the gridview. I now want to add edit and delete functionality. This should be fairly easy cos it's a build in feature of the gridview but alas... When the user clicks delete only one row on one table needs to be deleted thus I made a new query in my Datatable (DeleteissueQuery) that excpects an id
0
8062
by: ssims | last post by:
I've got a GridView that's sorted by a stored procedure with ROW_NUMBER: PROCEDURE dbo.GetCalendarsByStatusIDPaged ( @startRowIndex int, @maximumRows int, @statusID int ) AS
1
541
by: DC | last post by:
The problem I'm using the .NET GridView and FormView objects for the first time and im getting the error "An OleDbParameter with ParameterName '@ID' is not contained by this OleDbParameterCollection" whenI try to write a new record. Delete and Modify work fine its just the add record function causes the error.
13
10791
by: Tomasz Jastrzebski | last post by:
Helo All, The problem: GridView control does not render at all (header/footer) when the data source is empty. I have seen a similar question posted already, but I just can not believe there is no simple solution. I do not believe ASP.Net team took this, sort of, innovative approach and left no way out. Could anybody advise?
8
6257
by: Nick | last post by:
Hi there, I have a GridView in an UpdatePanel, each time the UpdatePanels Load event fires I set the DataSource and call DataBind of the grid view. This works great once, I add an item to the list and the control updates, my breakpoints get in in the UpdatePanel Load event. Only problem is on the second time, even though the code is executed, the GridView doesn't change. I have disabled the view state for the grid view but still the...
0
10199
Oralloy
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...
0
10032
jinu1996
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...
1
9979
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8861
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7393
isladogs
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...
0
6661
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3948
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
3
2810
bsmnconsultancy
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.