Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting Gridview problem

Status
Not open for further replies.

aspvbnetnerd

Programmer
May 16, 2006
278
SE
I am using a gridview. Many things are working great. RowEditing, PageIndexChanging, RowDeleting, RowUpdating but not the Sorting.

I have been googling a and trying sense last night but I cant get it to work. So I hope anyone here could help me. I am using a DataSet to bind to the data

This is the gridview code
Code:
<asp:GridView ID="GridProjects" 
    runat="server" 
    AutoGenerateColumns="False" 
    BackColor="#C2D4DA"
    BorderColor="#7EACB1" 
    BorderStyle="Solid" 
    BorderWidth="1px" 
    CellPadding="4" 
    Font-Names='"Lucida Grande", "Trebuchet MS"'
    Font-Size="10px" 
    ForeColor="Black" 
    GridLines="None" 
    OnRowCancelingEdit="GridProjects_RowCancelingEdit"
    OnRowDeleting="GridProjects_RowDeleting" 
    OnRowEditing="GridProjects_RowEditing" 
    OnPageIndexChanging="GridProjects_PageIndexChanging" 
    OnRowUpdating="GridProjects_RowUpdating" 
    AllowPaging="True" 
    AllowSorting="True" 
    PageSize="5" >
    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <Columns>
        <asp:CommandField ShowSelectButton="True" />
        <asp:CommandField ShowEditButton="True" />
        <asp:CommandField ShowDeleteButton="True" />
        <asp:BoundField DataField="CustomerID" 
                        HeaderText="CustomerID" 
                        InsertVisible="False"
                        ReadOnly="True" 
                        SortExpression="CustomerID" />
        <asp:BoundField DataField="ProjectID" 
                        HeaderText="ProjectID" 
                        InsertVisible="False"
                        ReadOnly="True" 
                        SortExpression="ProjectID" />
        <asp:BoundField DataField="Name" 
                        HeaderText="Customer" 
                        ReadOnly="True" 
                        SortExpression="Customer" />
        <asp:BoundField DataField="ProjectName" 
                        HeaderText="Project" 
                        ReadOnly="True" 
                        SortExpression="Project" />
        <asp:BoundField DataField="Deadline" 
                        HeaderText="Deadline" 
                        ReadOnly="True" 
                        SortExpression="Deadline">
            <HeaderStyle Width="150px" />
        </asp:BoundField>
        <asp:BoundField DataField="ProjectManager" 
                        HeaderText="Project leader" 
                        ReadOnly="True"
                        SortExpression="ProjectManager" />
        <asp:BoundField DataField="EstimatedTime" 
                        HeaderText="Time Estimated" 
                        ReadOnly="True"
                        SortExpression="EstimatedTime" />
        <asp:BoundField DataField="InvoiceTime" 
                        HeaderText="Invoice time" 
                        SortExpression="InvoiceTime" >
            <ControlStyle Font-Names="Lucida Grande,Lucida Sans Unicode,Verdana,Helvetica,Arial,sans-serif;"
                          Font-Size="10px" />
        </asp:BoundField>
        <asp:HyperLinkField DataNavigateUrlFields="Specification" 
                            DataNavigateUrlFormatString="Specification/{0}"
                            DataTextField="Specification" 
                            DataTextFormatString="Open" 
                            HeaderText="Specification"
                            Text="Specification" />
        <asp:TemplateField HeaderText="Developer" 
                           SortExpression="Developer">
            <EditItemTemplate>
                <asp:DropDownList ID="DropDownListDeveloper" 
                                  runat="server" 
                                  DataSourceID="SqlDataSource3"
                                  DataTextField="UserName" 
                                  DataValueField="UserID" 
                                  CssClass="DropDownListBox">
                </asp:DropDownList>
                <asp:SqlDataSource ID="SqlDataSource3" 
                                   runat="server" 
                                   ConnectionString="<%$ ConnectionStrings:g_ConnectionString %>"
                                   SelectCommand="Select UserID, CAST(FirstName As VarChar(50)) + ' ' + CAST(LastName As VarChar(50)) AS UserName FROM Users WHERE Developer = 1 Order By UserID">
                </asp:SqlDataSource>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label2" runat="server" Text='<%# Bind("UserName") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:ImageField DataImageUrlField="Picture" 
                        DataImageUrlFormatString="Pictures/{0}"
                        HeaderText="Status" 
                        ReadOnly="True">
        </asp:ImageField>
        <asp:TemplateField HeaderText="Status" SortExpression="Status">
            <EditItemTemplate>
                <asp:DropDownList ID="DropDownListStatus" 
                                  runat="server" 
                                  DataSourceID="SqlDataSource2"
                                  DataTextField="Name" 
                                  DataValueField="ProjectStatusID" 
                                  CssClass="DropDownListBox">
                </asp:DropDownList>
                <asp:SqlDataSource ID="SqlDataSource2" 
                                   runat="server" 
                                   ConnectionString="<%$ ConnectionStrings:g_ConnectionString %>"
                                   SelectCommand="Select ProjectStatusID, Name From ProjectStatus Order By ProjectStatusID">
                </asp:SqlDataSource>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Bind("Status") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
    <RowStyle BackColor="White" />
    <PagerStyle BackColor="#7EACB1" ForeColor="White" HorizontalAlign="Center" />
    <AlternatingRowStyle BackColor="#F4F9F8" />
</asp:GridView>

This is the cs for the page
Code:
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        initData();
    }
}

void initData()
{

    mDataAdapter = new DataAdapter();
    mDataAdapter.init(mConnectionString);

    DataSet ds = new DataSet();
    ds = mDataAdapter.getProjects();

    GridProjects.DataSource = ds;
    GridProjects.DataBind();

    ds = null;
    mDataAdapter.dispose();
    mDataAdapter = null;

}
[b]I don't know what i should type here[/b]
protected void GridProjects_Sorting(object sender, GridViewSortEventArgs e)
{

}

Regards
George
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top