473,386 Members | 1,832 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,386 software developers and data experts.

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="gvSearchList" runat="server"
AllowPaging="True"
AllowSorting="True"
AutoGenerateSelectButton="False"
AutoGenerateColumns="False"
PageSize="15"
style="width:70%"
OnPageIndexChanging="gvSearchList_PageIndexChangin g"
OnSorting="gvSearchList_Sorting"
OnSelectedIndexChanged="gvSearchList_SelectedIndex Changed">
<Columns>
<asp:BoundField DataField="Name"
HeaderText="File Name"
SortExpression="Name"
HeaderStyle-VerticalAlign="Bottom"
ItemStyle-HorizontalAlign="left"
ItemStyle-Width="45%" />

<asp:BoundField DataField="LastWriteTime"
HeaderText="Last Write Time"
SortExpression="LastWriteTime"
HeaderStyle-VerticalAlign="Bottom"
ItemStyle-HorizontalAlign="left"
ItemStyle-Width="40%" />

<asp:BoundField DataField="Length"
HeaderText="File Size"
ReadOnly="True"
SortExpression="Length"
HeaderStyle-VerticalAlign="Bottom"
ItemStyle-HorizontalAlign="center"
ItemStyle-Width="15%" />

</Columns>
</asp:GridView>

protected void Search_Click(object Sender, CommandEventArgs Args)
{
this.DirectoryList(this.txtSearch.Text);
}
protected void DirectoryList(string DirectoryPath)
{
DirectoryInfo dirInfo = new DirectoryInfo(Server.MapPath(str00));
this.gvSearchList.DataSource = dirInfo.GetFiles("*.*");
this.gvSearchList.DataBind();
}
protected void gvSearchList_SelectedIndexChanged(object Sender, EventArgs
e)
{

}
private string ConvertSortDirectionToSql(SortDirection sortDirection)
{
string newSortDirection = String.Empty;

switch (sortDirection)
{
case SortDirection.Ascending:
newSortDirection = "ASC";
break;

case SortDirection.Descending:
newSortDirection = "DESC";
break;
}

return newSortDirection;
}
protected void gvSearchList_PageIndexChanging(object sender,
GridViewPageEventArgs e)
{
gvSearchList.PageIndex = e.NewPageIndex;
gvSearchList.DataBind();
this.gvSearchList.Visible = true;
}
protected void gvSearchList_Sorting(object sender, GridViewSortEventArgs
e)
{
DataTable dataTable = gvSearchList.DataSource as DataTable;

if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
dataView.Sort = e.SortExpression + " " +
ConvertSortDirectionToSql(e.SortDirection);

gvSearchList.DataSource = dataView;
gvSearchList.DataBind();
}
}

Dec 1 '06 #1
2 3859
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.comwrote in message
news:GI**************@TK2MSFTNGHUB02.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
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: 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...
6
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...
0
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: ...
3
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...
0
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
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...
13
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...
8
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...

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.