1

我有一个这样的下拉列表:

<asp:DropDownList ID="ddlPortal2" runat="server" AutoPostBack="True">
        <asp:ListItem>Select</asp:ListItem>
        <asp:ListItem>TRAVELONG</asp:ListItem>
        <asp:ListItem>ONETRAVEL</asp:ListItem>
    </asp:DropDownList>

和带有 sqlconnection 的网格视图:

 <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" 
        GridLines="None" onrowcommand="GridView1_RowCommand" 
        AutoGenerateColumns="False">
        <Columns> 
       <asp:BoundField DataField="Portal" HeaderText="Portal" />
        <asp:BoundField DataField="TID" HeaderText="TID" />
        <asp:BoundField DataField="PNR" HeaderText="PNR" />
        <asp:BoundField DataField="TicketNumber" HeaderText="Ticket Number" />
        <asp:BoundField DataField="ESACCode" HeaderText="ESACCode" />
        <asp:BoundField DataField="WaiverCode" HeaderText="WaiverCode" />
        <asp:BoundField DataField="Remarks" HeaderText="Remarks" />
        <asp:BoundField DataField="UnusedTicketAmount" HeaderText="UnusedTicketAmount" />
        <asp:BoundField DataField="ddlUnusedAmount" HeaderText="ddlUnusedAmount" />
        <asp:BoundField DataField="AirlinePenality" HeaderText="AirlinePenality" />
        <asp:BoundField DataField="ddlAirlinePenality" HeaderText="ddlAirlinePenality" />
        <asp:BoundField DataField="NetRefundProcess" HeaderText="NetRefundProcess" />
        <asp:BoundField DataField="ddlNetRefundProcess" HeaderText="ddlNetRefundProcess" />
        <asp:BoundField DataField="RefundableCommission" HeaderText="RefundableCommission" />
        <asp:BoundField DataField="ddlRefundableCommission" HeaderText="ddlRefundableCommission" />
        <asp:BoundField DataField="CouponRefunded" HeaderText="CouponRefunded" />
        <asp:BoundField DataField="RefundType" HeaderText="RefundType" /> 
    </Columns>       
 <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:BartConnectionString %>" 
        SelectCommand="SELECT select * [Test]">
        </asp:SqlDataSource>

现在,当我从下拉列表中选择 Travelong 并按下搜索按钮时,gridview 中显示的所有数据都可以告诉我该怎么做。我该怎么做

4

3 回答 3

1

您可以使用SqlDataSource.FilterExpression 属性

于 2013-03-28T07:39:30.997 回答
1

使用SqlDataSource 的SelectParameters属性

<asp:DropDownList ID="ddlPortal2" runat="server" AutoPostBack="True">
    <asp:ListItem>Select</asp:ListItem>
    <asp:ListItem>TRAVELONG</asp:ListItem>
    <asp:ListItem>ONETRAVEL</asp:ListItem>
</asp:DropDownList>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:BartConnectionString %>" 
    SelectCommand="SELECT select * [Test] WHERE Portal = @Portal"">
      <selectparameters>
          <asp:controlparameter name="Portal" controlid="ddlPortal2" propertyname="SelectedValue"/>
      </selectparameters>
  </asp:sqldatasource>

参考

于 2013-03-28T07:54:01.837 回答
0

我得到了答案

    DataSet ds = new DataSet();
    SqlDataAdapter da = new SqlDataAdapter();
    SqlConnection con;
    if (ddlPortal2.SelectedIndex != 0)
    {
        con = new SqlConnection("Data Source=.;Initial Catalog=Bart;Integrated Security=True");
        con.Open();
        da = new SqlDataAdapter("select * from Test where Portal='"+ddlPortal2.SelectedValue+"' and CONVERT(VARCHAR(25), [DateTime], 101) between '" + tbFrom.Text + "' and '" + tbTo.Text + "'", con);
        da.Fill(ds);
        GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind();
        con.Close();
    }
    else if (ddlPortal2.SelectedValue == "All")
    {
        SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=Bart;Integrated Security=True");
        conn.Open();
        da = new SqlDataAdapter("Select * from Test where Portal=Portal", conn);
        da.Fill(ds);
        GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind();
        conn.Close();
    }
于 2013-03-28T13:56:59.713 回答