LinqDataSource WhereParameters,带有下拉列表和数据库中的字段

时间:2014-01-09 17:11:46

标签: c# sql linq

我想执行一个LINQ Listview where子句,其中包含两个where子句项:第一个来自Dropdownlist选项(这项工作正常)。我想从我的数据库(isAvailable)的表字段中添加另一个选择。你能解释一下如何使用表字段isAvaiable(bool类型)填充where子句的请求。我在C#中这样做。这是代码:

 <asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="ApointmentDataContext" 
    EnableDelete="True" EnableInsert="True" EnableUpdate="True" EntityTypeName="" 
    TableName="RendezVous" AutoGenerateWhereClause="True">
    <WhereParameters>
         <asp:ControlParameter 
              Name="DoctorName" 
              ControlID="DropDownList1" 
              PropertyName="SelectedValue"
              Type="String" />
    </WhereParameters>
 </asp:LinqDataSource>

 <div class="center">
     <asp:Label ID="lblDoctor" runat="server" Text="Choose a name"> </asp:Label>
     <div class="value-right"> 
         <asp:DropDownList ID="DropDownList1" runat="server" Width="180px" AutoPostBack="true" >
                    <asp:ListItem Text="Doct A" Value="Doc A" />
                    <asp:ListItem Text="Doct B" Value="Doc B" />
                    <asp:ListItem Text="Doct C" Value="Doc C" />
         </asp:DropDownList> 
    </div>  
 </div>

 <LayoutTemplate>
    <table runat="server">
        <tr runat="server">
            <td runat="server">
               <table id="itemPlaceholderContainer" runat="server" border="0" style="">
                  <tr runat="server" style="">
                      <th runat="server"></th>
                         <th runat="server">DoctName</th>
                         <th runat="server">date</th>
                         <th runat="server">hour</th>
                         <th runat="server">patientName</th>
                         <th runat="server">isAvailable</th>
                       </tr>
                       <tr id="itemPlaceholder" runat="server">
                       </tr>
               </table>
            </td>
        </tr>
        <tr runat="server">
            <td runat="server" style="">
                <asp:DataPager ID="DataPager1" runat="server">
                   <Fields>
                      <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" 
                         ShowLastPageButton="True" />
                   </Fields>
                </asp:DataPager>
            </td>
        </tr>
        </table>
            </LayoutTemplate>
            <SelectedItemTemplate>
                <tr style="">
                  <td>
                     <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" 
                        Text="Delete" />
                     <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                  </td>
                  <td>
                     <asp:Label ID="lblDoctorName" runat="server" Text='<%# 
                         Eval("DoctorName") %>' />
                  </td>
                  <td>
                     <asp:Label ID="lblDate" runat="server" Text='<%# Eval("date") %>' />
                  </td>
                  <td>
                     <asp:Label ID="lblhour" runat="server" Text='<%# Eval("hour") %>' />
                    </td>
                  <td>
                     <asp:Label ID="lblPatient" runat="server" Text='<%# Eval("patientName") %>' 
                        />
                  </td>
                  <td>
                     <asp:Label ID="isAvailable" runat="server" Text='<%# Eval("isAvailable") %>'
                         />
                  </td>
                </tr>
            </SelectedItemTemplate>
        </asp:ListView>

我需要将字段isAvailable放在where子句中,可以搞清楚。感谢

0 个答案:

没有答案