GridView won't page (Non SQL Source)

S

sck10

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_PageIndexChanging"
OnSorting="gvSearchList_Sorting"
OnSelectedIndexChanged="gvSearchList_SelectedIndexChanged">
<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();
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top