网格视图没有通过下拉刷新。

时间:2013-09-18 05:11:56

标签: c# asp.net .net gridview

<asp:DropDownList ID="RequestType1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
                        <asp:ListItem>All</asp:ListItem>
                        <asp:ListItem Value="Stock_Market">Stock Market</asp:ListItem>
                        <asp:ListItem Value="Night_Shift">Night Shift</asp:ListItem>
                        <asp:ListItem Value="Air_Port">Air Port</asp:ListItem>
                        <asp:ListItem>Other</asp:ListItem>
                    </asp:DropDownList>

 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource1" Font-Size="Small" ForeColor="#333333" GridLines="None" Width="810px" ShowHeaderWhenEmpty="True">

  <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConString %>" SelectCommand="select req.request_no ,emp.employee_name,req.requested_date, req.requested_time, req.requested_from, req.requested_to,req.reason_data from Request_List req, Employee emp where req.added_by=emp.employee_id and group_no IS NULL"></asp:SqlDataSource>

我有一个gridview和一个下拉列表和一个sqldatasource,当页面加载时,gridview将从sqldata源加载默认查询。使用下拉列表选择每个选项时,将按如下方式加载相应的查询。

 if (RequestType1.Text == "All")
        {

            SqlDataSource1.SelectCommand = "select req.request_no ,emp.employee_name,req.requested_date, req.requested_time, req.requested_from, req.requested_to,req.reason_data from Request_List req, Employee emp where req.added_by=emp.employee_id and group_no IS NULL";

        }
        else if (RequestType1.Text == "Stock_Market")
        {
            SqlDataSource1.SelectCommand = "select req.request_no ,emp.employee_name,req.requested_date, req.requested_time, req.requested_from, req.requested_to,req.reason_data from Request_List req, Employee emp where req.added_by=emp.employee_id and req.service_type='Stock_Market ' and group_no IS NULL";

        }
        else if (RequestType1.Text == "Night_Shift")
        {
            SqlDataSource1.SelectCommand = "select req.request_no ,emp.employee_name,req.requested_date, req.requested_time, req.requested_from, req.requested_to,req.reason_data from Request_List req, Employee emp where req.added_by=emp.employee_id and req.service_type='Night_Shift' and group_no IS NULL";

        }
        else if (RequestType1.Text == "Air_Port")
        {

            SqlDataSource1.SelectCommand = "select req.request_no ,emp.employee_name,req.requested_date, req.requested_time, req.requested_from, req.requested_to,req.reason_data from Request_List req, Employee emp where req.added_by=emp.employee_id and req.service_type='Air_Port' and group_no IS NULL";
        }
        else if (RequestType1.Text == "Other")
        {
            SqlDataSource1.SelectCommand = "select req.request_no ,emp.employee_name,req.requested_date, req.requested_time, req.requested_from, req.requested_to,req.reason_data from Request_List req, Employee emp where req.added_by=emp.employee_id and req.service_type='Other' and group_no IS NULL";

        }

但是对于'All'选项,gridview没有刷新。它有这个查询

 SqlDataSource1.SelectCommand = "select req.request_no ,emp.employee_name,req.requested_date, req.requested_time, req.requested_from, req.requested_to,req.reason_data from Request_List req, Employee emp where req.added_by=emp.employee_id and group_no IS NULL";

但是当我添加其他一些查询时,它确实会刷新。关系是sqldata源的默认查询和选项'All'的查询是相同的。那么,任何解决方案如何加载值?

1 个答案:

答案 0 :(得分:0)

试试这个:

       if (RequestType1.Text == "All")
        {

            SqlDataSource1.SelectCommand = "select req.request_no ,emp.employee_name,req.requested_date, req.requested_time, req.requested_from, req.requested_to,req.reason_data from Request_List req, Employee emp where req.added_by=emp.employee_id and group_no IS NULL";

        }
        else if (RequestType1.Text == "Stock_Market")
        {
            SqlDataSource1.SelectCommand = "select req.request_no ,emp.employee_name,req.requested_date, req.requested_time, req.requested_from, req.requested_to,req.reason_data from Request_List req, Employee emp where req.added_by=emp.employee_id and req.service_type='Stock_Market ' and group_no IS NULL";

        }
        else if (RequestType1.Text == "Night_Shift")
        {
            SqlDataSource1.SelectCommand = "select req.request_no ,emp.employee_name,req.requested_date, req.requested_time, req.requested_from, req.requested_to,req.reason_data from Request_List req, Employee emp where req.added_by=emp.employee_id and req.service_type='Night_Shift' and group_no IS NULL";

        }
        else if (RequestType1.Text == "Air_Port")
        {

            SqlDataSource1.SelectCommand = "select req.request_no ,emp.employee_name,req.requested_date, req.requested_time, req.requested_from, req.requested_to,req.reason_data from Request_List req, Employee emp where req.added_by=emp.employee_id and req.service_type='Air_Port' and group_no IS NULL";
        }
        else if (RequestType1.Text == "Other")
        {
            SqlDataSource1.SelectCommand = "select req.request_no ,emp.employee_name,req.requested_date, req.requested_time, req.requested_from, req.requested_to,req.reason_data from Request_List req, Employee emp where req.added_by=emp.employee_id and req.service_type='Other' and group_no IS NULL";

        }
        GridView1.DataSourceID = SqlDataSource1.ID;
        GridView1.DataBind();