Sorting GridView

newbeee

Member
Joined
Sep 27, 2007
Messages
19
Programming Experience
Beginner
Do I need to do anything else special in order to sort columns in a GridView that result generate based on a user input from a previous page?

Error Msg receive when I attempt to click on one of the columns to sort:
NullReferenceException was unhandled by user code
Use the "new" keyword to create an object instance.
Check to determine if the object is null before calling the method

VB.NET:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

      [COLOR="Red"]  If Not (PreviousPage.getInput = " ") [/COLOR]Then
            Dim rpData As New clsACData
            GridView1.DataSource = rpData.GetDeceasedReport (PreviousPage.getInput)
            GridView1.DataBind()
        End If
    End Sub

Here's how I create my gridview in .aspx page
HTML:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="false" Width="500px">       
        <Columns>

          <asp:TemplateField HeaderText="ID" SortExpression="ID">
            <ItemTemplate>
                <asp:Label ID="ID" runat="server" Text='<%# Eval("ID") %>' Width="70px"></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
          
        <asp:TemplateField HeaderText="First Name" SortExpression="FirstName">
            <ItemTemplate>
                <asp:Label ID="Name" runat="server" Text='<%# Eval("FirstName") %>' Width="80px"></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>

        <asp:TemplateField HeaderText="Last Name" SortExpression="LastName">
            <ItemTemplate>
                <asp:Label ID="LastName" runat="server" Text='<%# Eval("LastName") %>' Width="80px"></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
         </Columns>
    </asp:GridView>

Thanks in advance.
 
Last edited by a moderator:

Latest posts

Back
Top