我的 DetailsView 始终为空白。我已经在 QueryBuilder 中测试了两个数据源,它们都返回值。我怀疑 PoweredEquipDetails 中的参数值分配有问题,它们被设置为 GridView1 中的 SelectedValue,但我不知道为什么它不起作用。
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="PoweredEquipHeader" DataKeyNames="Model,Serial">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="Model" HeaderText="Model" ReadOnly="True"
SortExpression="Model" />
<asp:BoundField DataField="Serial" HeaderText="Serial" ReadOnly="True"
SortExpression="Serial" />
</Columns>
<SelectedRowStyle BackColor="#FF6600" />
</asp:GridView>
<asp:SqlDataSource ID="PoweredEquipHeader" runat="server"
ConnectionString="<%$ ConnectionStrings:CPECConnectionString %>"
SelectCommand="Select t1.Model, t1.Serial From Powered_Equip t1 Where TechID = @TechID And Store = @Store">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="TECH01" Name="TechID"
QueryStringField="Tech" />
<asp:QueryStringParameter DefaultValue="0000" Name="Store"
QueryStringField="Store" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="PoweredEquipDetail" runat="server"
ConnectionString="<%$ ConnectionStrings:CPECConnectionString %>"
SelectCommand="SELECT t1.Serial, t1.Model, t1.Status, t1.[Trailer VIN], t2.Tag, t2.State, t2.ExpMonth, t2.ExpYear FROM Powered_Equip AS t1 INNER JOIN Trailers AS t2 ON t1.[Trailer VIN] = t2.VIN WHERE (t1.Serial = @Serial) AND (t1.Model = @Model)">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="Serial"
PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="GridView1" Name="Model"
PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
<asp:DetailsView ID="DetailsView1" runat="server"
DataSourceID="PoweredEquipDetail" DataKeyNames="Serial,Model">
<Fields>
<asp:BoundField DataField="Serial" HeaderText="Serial" ReadOnly="True"
SortExpression="Serial" />
<asp:BoundField DataField="Model" HeaderText="Model"
ReadOnly="True" SortExpression="Model" />
<asp:BoundField DataField="Status" HeaderText="Status" ReadOnly="True"
SortExpression="Status" />
<asp:BoundField DataField="Trailer VIN" HeaderText="Trailer VIN" ReadOnly="True"
SortExpression="Trailer VIN" />
<asp:BoundField DataField="Tag" HeaderText="Tag" ReadOnly="True"
SortExpression="Tag" />
<asp:BoundField DataField="State" HeaderText="State" ReadOnly="True"
SortExpression="State" />
<asp:BoundField DataField="ExpMonth" HeaderText="ExpMonth" ReadOnly="True"
SortExpression="ExpMonth" />
<asp:BoundField DataField="ExpYear" HeaderText="ExpYear" ReadOnly="True"
SortExpression="ExpYear" />
</Fields>
</asp:DetailsView>
</form>
编辑:所以我相信发生的事情是DetailsView参数分配中GridView的SelectedValue始终是Model,而不是我的DataValueKeys中指定的Model和Serial。如果设备项具有相同值的型号和序列号(即型号 118 序列号 118),则会填充详细信息视图。但是在模型和序列不同的任何情况下(几乎所有其他情况),DetailsView 都是空白的。那么如何获得两个不同的 SelectedValues 来为两个不同的 ControlParameters 赋值呢?