当使用whereAutogenerate时,是否可以组合where子句?

时间:2014-01-14 15:41:18

标签: c# sql linq

我想将这些组合到where子句中。我收到了错误 当AutoGenerateWhereClause为true时,LinqDataSource不支持Where属性。

第一个where子句来自apointement表。我想只选择列IsAvailable = True的行。

另一个来自下拉列表的地方。我想知道如何结合,但如果可行的话。谢谢

 <asp:LinqDataSource ID="LinqDataSource1" runat="server"
      ContextTypeName="DoctorDataContext" EnableDelete="True" EnableInsert="True" 
      EnableUpdate="True" EntityTypeName="" TableName="Apointement" 
      AutoGenerateWhereClause="True"
      Where="@IsAvailable = True"> 

      <WhereParameters>
         <asp:ControlParameter 
             Name="doctorName" 
             ControlID="DropDownList1" 
             PropertyName="SelectedValue"
             Type="String" />
      </WhereParameters>

 </asp:LinqDataSource>

 <div class="center">

 <asp:Label ID="lbldoctorName" runat="server" Text="Choose a doctor">   
 </asp:Label>

 <div class="value-right"> 
     <asp:DropDownList ID="DropDownList1" runat="server" Width="180px" AutoPostBack="true" 
           OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" >
           <asp:ListItem Text="doctorA" Value="doctorA" />
           <asp:ListItem Text="doctorB" Value="doctorB" />
           <asp:ListItem Text="doctorC" Value="doctorC" />

     </asp:DropDownList> 

2 个答案:

答案 0 :(得分:0)

将另一个<asp:ControlParameter添加到<WhereParameters>元素。我不是LinqDataSources的最新版本所以我不知道语法,但是你要指定IsAvailable列的值为True,或者可能是1.

答案 1 :(得分:0)

我所做的是删除AutoGenerateWhereClause =“True”,它唯一的问题是第一次显示下拉列表中的所有选项。

<asp:LinqDataSource ID="LinqDataSource1" runat="server"
  ContextTypeName="DoctorDataContext" EnableDelete="True" EnableInsert="True" 
  EnableUpdate="True" EntityTypeName="" TableName="Apointement" 
  Where="@IsAvailable = True"> 
  <WhereParameters>
     <asp:ControlParameter 
         Name="doctorName" 
         ControlID="DropDownList1" 
         PropertyName="SelectedValue"
         Type="String" />
  </WhereParameters>

</asp:LinqDataSource>