2013-04-24 92 views
0

我有嵌套在GridView中的DropDownList。如何過濾DropDownList數據源,僅顯示活動的db行(列爲活動的位類型)或當前選定的DropDownList的值?GridView中的已過濾DropDownList

以下部分代碼不起作用。有什麼辦法如何綁定到curent的GridView行數據(通過標記)?

<asp:GridView ID="GridView" runat="server" AllowPaging="True" 
    AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="PlasticTypeId" 
    DataSourceID="dsPlasticTypes"> 
    <Columns> 
     <asp:CommandField ShowEditButton="True" /> 
     <asp:CheckBoxField DataField="Active" HeaderText="Active" SortExpression="Active" /> 
     <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" /> 
     <asp:TemplateField HeaderText="<%$ Resources:Labels, PlasticFamily %>" SortExpression="PlasticFamily.Name"> 
      <ItemTemplate> 
       <asp:Label ID="Label1" runat="server" Text='<%# Eval("PlasticFamily.Name") %>'/> 
      </ItemTemplate> 
      <EditItemTemplate> 
       <asp:DropDownList ID="ddlFamilies" runat="server" DataSourceID="dsFamilies" DataValueField="PlasticFamilyId" 
        DataTextField="Name" SelectedValue='<%# Bind("PlasticFamilyId") %>'/> 
       <asp:EntityDataSource ID="dsFamilies" runat="server" 
        ConnectionString="name=PlasticsDbEntities" OrderBy="it.Name" 
        DefaultContainerName="PlasticsDbEntities" EnableFlattening="False" 
        EntitySetName="PlasticFamilies" 
        Where="it.Active==true || [email protected]"> 
        <WhereParameters> 
         <asp:ControlParameter Name="control" ControlID="ddlFamilies" PropertyName="SelectedValue" Type="Int32" /> 
        </WhereParameters> 
       </asp:EntityDataSource> 
      </EditItemTemplate> 
     </asp:TemplateField> 
    </Columns> 
</asp:GridView> 
+0

你能發表更詳細的關於你的要求嗎? – 2013-04-24 13:50:23

+0

我建議你另一個解決方案,基於'DataView'和'RowFilter'鏈接:http://msdn.microsoft.com/fr-fr/library/system.data.dataview.rowfilter(v=vs.80).aspx – 2013-04-24 11:34:25

回答

1

我已經通過將綁定到相同的字段DropDownList的上方的隱藏字段,並用它作爲ControlParameter過濾數據源解決了這個。

<asp:TemplateField HeaderText="<%$ Resources:Labels, PlasticFamily %>" SortExpression="PlasticFamily.Name"> 
    <ItemTemplate> 
     <asp:Label ID="Label1" runat="server" Text='<%# Eval("PlasticFamily.Name") %>' /> 
    </ItemTemplate> 
    <EditItemTemplate> 
     <asp:HiddenField ID="hfPlasticFamilyId" runat="server" Value='<%# Eval("PlasticFamilyId") %>' /> 
     <asp:DropDownList ID="ddlFamilies" runat="server" DataSourceID="dsFamilies" 
      DataTextField="Name" DataValueField="PlasticFamilyId" SelectedValue='<%# Bind("PlasticFamilyId") %>' /> 
     <asp:EntityDataSource ID="dsFamilies" runat="server" 
      ConnectionString="name=PlasticsDbEntities" 
      DefaultContainerName="PlasticsDbEntities" EnableFlattening="False" 
      EntitySetName="PlasticFamilies" OrderBy="it.Name" 
      Where="it.Active==true || [email protected]ntrol"> 
      <WhereParameters> 
       <asp:ControlParameter ControlID="hfPlasticFamilyId" Name="control" 
        PropertyName="Value" Type="Int32" /> 
      </WhereParameters> 
     </asp:EntityDataSource> 
    </EditItemTemplate> 
</asp:TemplateField>