【问题标题】:show data in datalist using RangeExpression使用 RangeExpression 在数据列表中显示数据
【发布时间】:2014-02-28 14:28:51
【问题描述】:

我有两个显示最低和最高价格的下拉列表。

我想使用 RangeExpression 在另一个页面中显示这两个下拉列表值之间的所有产品范围。

两个下拉列表都在母版页上。现在,当我点击提交按钮时,所有产品都应显示在该价格范围内的另一个页面中。

那么,我该怎么办?我应该使用什么作为我将传递给它的查询字符串?

我已经这样做了:

<asp:LinqDataSource ID="LinqDataSource1" runat="server" 
     ContextTypeName="linqextenderDataContext" EntityTypeName="" 
     TableName="Products" Where="Category == @Category">
     <WhereParameters>
         <asp:ControlParameter ControlID="dropcategory" Name="Category" 
              PropertyName="SelectedValue" Type="String" />
     </WhereParameters>
 </asp:LinqDataSource>
 <asp:QueryExtender ID="QueryExtender1" runat="server"
      TargetControlID="LinqDataSource1">
      <asp:RangeExpression DataField="Price" MinType="Inclusive"
           MaxType="Inclusive">
           <asp:ControlParameter ControlID="dropmin" Type="Int32"
                PropertyName="SelectedValue" />
           <asp:ControlParameter ControlID="dropmax" Type="Int32" 
                PropertyName="SelectedValue"/>
      </asp:RangeExpression>
  </asp:QueryExtender>

  <asp:Button ID="btnsubmit" runat="server" Text="Submit" 
       style="margin-left:50px" onclick="btnsubmit_Click"/>

现在我想在另一个页面中显示所有数据,所以当我将其重定向到另一个页面时,我应该传递什么?

protected void btnsubmit_Click(object sender, EventArgs e)
{
   Response.Redirect("products.aspx");        
}

【问题讨论】:

    标签: asp.net c#-4.0 linq-to-sql query-string query-extender


    【解决方案1】:

    你已经很接近了。

    protected void btnsubmit_Click(object sender, EventArgs e)
    {
        Response.Redirect(String.Format("products.aspx?min={0}&max={1}",
                          dropmin.SelectedValue, dropmax.SelectedValue);
    }
    

    然后在您的页面加载事件中,从查询字符串中读取最小值和最大值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-29
      • 2016-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-23
      相关资源
      最近更新 更多