我有一個簡單的GridView(ID爲'GridViewAttribs'),它顯示數據庫中的一些值。我希望有一個(嵌套的?)ListView,但由於某些原因,我不能使用asp:ControlParameter ControlID =「GridViewAttribs」PropertyName,因爲在我的(嵌套的)ListView中沒有返回結果。無法從GridView的TemplateField SELECT語句中獲取/使用ControlParameter
如果我不使用ControlParameter並硬編碼ListView的SELECT語句,那麼一切都按預期工作。
這裏是我的代碼:
<asp:SqlDataSource ID="SqlDataSourceAttribHeadings" runat="server"
ConnectionString="<%$ ConnectionStrings:customer_support_devConnectionString %>"
ProviderName="<%$ ConnectionStrings:customer_support_devConnectionString.ProviderName %>"
SelectCommand="SELECT equipment_attrib_heading_id, equipment_model_id, equipment_attrib_name FROM equipment_new_attrib_headings WHERE (equipment_model_id = @equipment_model_id) AND (equipment_attrib_heading_deleted = 0) ORDER BY equipment_attrib_name">
<SelectParameters>
<asp:SessionParameter DefaultValue="" Name="equipment_model_id"
SessionField="EquipmentModelID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridViewAttribs" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataKeyNames="equipment_attrib_heading_id"
DataSourceID="SqlDataSourceAttribHeadings" ForeColor="#333333" GridLines="None"
style="margin-right: 0px">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="equipment_attrib_heading_id"
HeaderText="equipment_attrib_heading_id" ReadOnly="True"
SortExpression="equipment_attrib_heading_id" />
<asp:BoundField DataField="equipment_model_id" HeaderText="equipment_model_id"
SortExpression="equipment_model_id" />
<asp:BoundField DataField="equipment_attrib_name"
HeaderText="equipment_attrib_name" SortExpression="equipment_attrib_name" />
<asp:TemplateField HeaderText="equipment_attrib_value_details" SortExpression="equipment_attrib_value_details">
<ItemTemplate>
<asp:SqlDataSource ID="SqlDataSourceAttribValues" runat="server"
ConnectionString="<%$ ConnectionStrings:customer_support_devConnectionString %>"
ProviderName="<%$ ConnectionStrings:customer_support_devConnectionString.ProviderName %>"
SelectCommand="SELECT [equipment_attrib_value_details] FROM [equipment_new_attrib_values] WHERE (equipment_attrib_heading_id = @head_id) AND (equipment_id = @equipment_id) AND (equipment_attrib_value_deleted = 0)">
<SelectParameters>
<asp:QueryStringParameter Name="equipment_id" QueryStringField="id"
Type="Int32" />
<asp:ControlParameter ControlID="GridViewAttribs"
Name="head_id" PropertyName="SelectedDataKey.Values[equipment_attrib_heading_id]" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:ListView ID="ListViewAttribValues" runat="server"
DataSourceID="SqlDataSourceAttribValues">
<EmptyDataTemplate>
<table runat="server" style="">
<tr><td>No data was returned.</td></tr>
</table>
</EmptyDataTemplate>
<ItemTemplate>
<tr style="">
<td><asp:Label ID="equipment_attrib_value_detailsLabel" runat="server" Text='<%# Eval("equipment_attrib_value_details") %>' /></td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table ID="itemPlaceholderContainer" runat="server" border="0" style="">
<tr ID="itemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
GridView控件顯示的所有列精除「equipment_attrib_value_details」欄在那裏我得到「未返回的數據。」
但是,如果我拿出的asp:ControlParameter它呼籲@head_id和使用硬編碼的SELECT語句,然後我看到正確的(雖然是硬編碼)值:
SelectCommand="SELECT [equipment_attrib_value_details] FROM [equipment_new_attrib_values] WHERE (equipment_attrib_heading_id = 3) AND (equipment_id = @equipment_id) AND (equipment_attrib_value_deleted = 0)">
因此,出於某種原因,它這樣看來的「equipment_attrib_heading_id」的GridViewAttribs值不被傳遞到/拾起嵌套的asp:ControlParameter
在關閉的機會,我也試着更換:
PropertyName="SelectedDataKey.Values[equipment_attrib_heading_id]"
有了:
PropertyName="SelectedValue"
但這並沒有解決這個問題要麼,仍然沒有被返回的數據。
如果有幫助,我使用ASP.NET4(vb)的Visual Studio 2010。
GENIUS!完美的作品!但我不明白爲什麼這個作品?你能否進一步闡明我做錯了什麼? – Rich