对象数据源没有过滤我的listview?

时间:2010-01-27 17:36:57

标签: c# listview

我正在尝试通过对象数据源使用文本框控件来过滤列表视图。但是,当我添加任何东西时都没有任我之前创造了类似的东西,所有的代码几乎都是一样的。任何人都有任何想法'我错过了什么?

<asp:TextBox ID="namefilter" runat="server" />
    <asp:Button ID="button1" runat="server" />

    <asp:ListView DataSourceID="DataSource" ID="ListView1" runat="server" DataKeyNames="ID" InsertItemPosition="LastItem">
    <LayoutTemplate>

        <table cellspacing="1" cellpadding="1" border="0" bgcolor="#6699cc" width="100%" >
        <tr>
            <th>&nbsp;</th>
            <th>&nbsp;</th>
            <th><span class="Caption1">Name</span></th>
            <th><span class="Caption1">Phone</span></th>
        </tr>

        <tr id="itemPlaceholder" runat="server" />
        </table>

    </LayoutTemplate>

    <ItemTemplate>
        <tr style="background-color: White;" >
            <td><asp:LinkButton ID="btnEdit" runat="server" Text="Edit" CommandName="Edit" /></td>
            <td><asp:LinkButton ID="btnDelete" runat="server" Text="Delete" CommandName="Delete" /></td>
            <td align="center"><%# DataBinder.Eval(Container, "DataItem.Name")%>           </td>
            <td align="center"><%# DataBinder.Eval(Container, "DataItem.Phone")%>          </td>
        </tr>                                                                            
    </ItemTemplate>

    <EditItemTemplate>
        <tr style="background-color: White;" >
            <td><asp:LinkButton ID="btnSave" runat="server" Text="Save" CommandName="Update" /></td>
            <td><asp:LinkButton ID="btnCancel" runat="server" Text="Cancel" CommandName="Cancel" /></td>
            <td><asp:TextBox ID="EditName" runat="server" Text='<%# Bind("Name") %>' /></td>
            <td><asp:TextBox ID="EditPhone" runat="server" Text='<%# Bind("Phone") %>' /></td>
        </tr>                                                     
    </EditItemTemplate>
    <InsertItemTemplate>
        <tr bgcolor="#6699cc" >
            <td><asp:LinkButton ID="InsertButton" CommandName="Insert" runat="server" Text="Insert" ValidationGroup="add" CssClass="Caption1" /> </td>
            <td><asp:LinkButton ID="CancelButton" CommandName="Cancel" runat="server" Text="Cancel" CausesValidation="false" CssClass="Caption1" /></td>
            <td> <asp:TextBox ID="InsertName" runat="server" Text='<%# Bind("Name") %>' ValidationGroup="insert" /> </td>
            <td><asp:TextBox ID="InsertPhone" runat="server" Text='<%# Bind("Phone") %>' />  </td>
    </InsertItemTemplate>

</asp:ListView>


<asp:LinqDataSource 
        ContextTypeName="assembly" 
        EnableUpdate="true" 
        EnableDelete="true" 
        EnableInsert="true"
        ID="DataSource" 
        OrderBy="Email desc" 
        runat="server" 
        TableName="Contacts" 
        AutoSort="true" 
         >
<whereParameters> 
    <asp:ControlParameter ControlID="emailfilter" Name="Email" PropertyName="Text" Type="String" ConvertEmptyStringToNull="false"   />
</whereParameters>
</asp:LinqDataSource>

1 个答案:

答案 0 :(得分:1)

d'oh,忘了在linqdatasource中添加where子句的排序..浪费了3个小时!

   <asp:LinqDataSource 
        ContextTypeName="Immediacy.VS.Plugins.DBML.VisitScotlandDataContext" 
        EnableUpdate="true" 
        EnableDelete="true" 
        EnableInsert="true"
        ID="DataSource" 
        OrderBy="Email desc" 
        runat="server" 
        TableName="Contacts" 
        AutoSort="true" 
        Where='(@Email == null) || (Email == @Email)' 
         >