按下拉列表对转发器值进行排序

时间:2019-04-19 03:11:54

标签: c# asp.net

这是我的问题, 我有中继器控件,其中显示了产品和价格,还具有下拉列表,其值从低到高,从高到低。我想按价格从下拉列表中的选定值从低到高和从高到低的顺序对转发器值进行排序。

     <asp:Repeater ID="rpt3"  runat="server">
         <ItemTemplate>


         <div class="col-lg-3 col-md-6 mb-4">
            <div class="card h-60">

               <asp:Image ID="Image1" class="card-img-top"   ImageUrl='<%#Eval("pic1", "pics/{0}") %>' Height="160px"   runat="server" />

        <div class="cardnew" >
              <p class="name cap"   style=" font-size: 12px;margin-top:0px"> <%#Eval("name") %></p>
               <p class="card-title name cap" style="color: #000000; font-size: 15px;width:auto;margin-bottom:2px;margin-top:5px"><%#Eval("adtitle") %></p>
                 <asp:Image ID="Image2" CssClass="imgn"  ImageUrl="~/images/Star_Gold-512.png" Height="20" Width="15" runat="server" />
        </div>

      <div class="card-footer" style="text-align:center">
              <p>Starting From : <%#Eval("rate") %> </p>
      </div>
    </div>
  </div>

       </ItemTemplate>
         </asp:Repeater>

隐藏代码

     SqlConnection myconn;
    SqlCommand mycomm;
    myconn = new     SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
    string q = ("SELECT postad.adid, postad.adtitle, postad.rate,postad.name, postad.date, postad.pic1, addstate.statename, addcity.cityname, addsubcat.scatname, addcat.catname FROM addcity INNER JOIN addstate INNER JOIN addsubcat INNER JOIN postad INNER JOIN addcat ON postad.cat = addcat.catid ON addsubcat.subcatid = postad.scat ON addstate.stateid = postad.state ON addcity.cityid = postad.city WHERE (postad.scat = @scat) and (postad.expiry >= Getdate()) and postad.status='Approved'");
    mycomm = new SqlCommand(q, myconn);
    mycomm.Parameters.AddWithValue("@scat", Request.QueryString["scid"]);

    DataTable dt = new DataTable();
    SqlDataAdapter da = new SqlDataAdapter(mycomm);
    myconn.Open();
    da.Fill(dt);
    if (dt.Rows.Count > 0 && dt.Rows[0][0] != string.Empty)
    {
        rpt3.DataSource = dt;
        rpt3.DataBind();
    }
    else
    {
        rpt3.DataSource = null;
        rpt3.DataBind();
    }
    myconn.Close();

0 个答案:

没有答案