CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2006
    Posts
    1

    Issues with GridView in ASP.NET 2.0

    Please share all the issues with GridView in ASP.NET 2.0 under this thread.

    I have a very serious problem working with GridView.
    I'm trying to use DirectoryInfo to retrieve file information to display in the GridView and this works fine...

    Now I was to sort (Ascending & Descending) the files on click of Cloumn click...

    But now since GridView has inbuilt sorting, was tying to use the same... And I faced 2 issues while doing so...
    Below is all the details with the code:

    ASPX Code:
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:GridView ID="GridView1" AllowSorting="true" runat="server" AutoGenerateColumns="False" OnSorting="GridView1_Sorting">
    <Columns>
    <asp:BoundField HeaderText="Full Name" DataField="Name" SortExpression="Name" />
    <asp:BoundField HeaderText="Last Write Time" DataField="LastWriteTime" SortExpression="LastWriteTime" />
    <asp:BoundField HeaderText="File Size" DataField="Length" SortExpression="Length" DataFormatString="{0:#,### bytes}"/>
    <asp:BoundField HeaderText="Last Access Time" DataField="LastAccessTime" SortExpression="LastAccessTime" />
    </Columns>
    </asp:GridView>
    </div>
    </form>
    </body>

    Issue 1:
    Earlier I did not have OnSorting="GridView1_Sorting" attribute and that time I received "Gridview fired event Sorting which wasn't handled." error for which I added OnSorting="GridView1_Sorting and a code behind code.

    Issue 2:
    After I inserted GridView1_Sorting(object sender, GridViewSortEventArgs e) in aspx.cs file,

    void GridView1_Sorting(object sender, GridViewSortEventArgs e)
    {
    GridView1.Sort (e.SortExpression, e.SortDirection);
    GridView1.DataSource = fileInfoArray;
    GridView1.DataBind();
    }
    This code goes into Infinite Loop and when I tried to search something on the internet I found one more piece of code...i.e.
    protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
    {
    DataTable m_DataTable = GridView1.DataSource as DataTable;

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

    GridView1.DataSource = m_DataView;
    GridView1.DataBind();
    }
    }

    But the problem in this code is...
    DataTable m_DataTable = GridView1.DataSource as DataTable;
    Retuns me a NULL Datatable.

    I would be looking for all kind of help and pointers to fix this problem...

    Thanks in Advance,
    J.S.
    Last edited by jsheth; February 1st, 2006 at 01:49 PM.

  2. #2
    Join Date
    Jan 2011
    Posts
    6

    Re: Issues with GridView in ASP.NET 2.0

    It is am nice post......

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured