1

多くの列を持つ編集可能なグリッドビューがあります。そのうちの2つは100mPlotとSubPlotです。サブプロットは一意ではありませんが(1A、1B、1C、および1D)、100mPlot+SubPlotは一意の値のセットを作成します。

ユーザーが[編集]をクリックすると、[サブプロット]列にドロップダウンリストが表示されます。このリストは、100mPlotの値に基づいている必要があります。したがって、SubPlotの正しい値を表示するには、100mPlot列の値を、SubPlotドロップダウンリストにバインドされるsqldatasourceへのパラメーターとして渡す必要があります。どうすればいいですか?

<asp:BoundField DataField="100mPlot" HeaderText="100m plot" 
     SortExpression="100mPlot" ReadOnly="True" />
<asp:TemplateField HeaderText="SubPlot" SortExpression="SubPlot">
     <EditItemTemplate>
         <asp:DropDownList ID="DropDownList1" runat="server" 
             DataSourceID="dsSubPlotNames" 
             DataTextField="SiteID" DataValueField="SiteID" 
             SelectedValue='<%# Bind("SiteID") %>'
             AppendDataBoundItems="True">
             <asp:ListItem Value=""></asp:ListItem>
         </asp:DropDownList>
         <asp:SqlDataSource ID="dsSubPlotNames" runat="server" 
             ConnectionString="<%$ ConnectionStrings:WERCMTX %>" SelectCommand="exec [339_PPM].usp_SubPlotNames_Select @100mPlotSiteID;">
             <SelectParameters>
                 <asp:Parameter Name="100mPlotSiteID" />
             </SelectParameters>
          </asp:SqlDataSource>
       </EditItemTemplate>
       <ItemTemplate>
           <asp:Label ID="Label3" runat="server" Text='<%# Bind("SubPlot")%>'></asp:Label>
       </ItemTemplate>
</asp:TemplateField>

ご覧のとおり、パラメータ名「100mPlotSiteID」は100mPlot列から取得する必要があります。これを他にどのように明確に説明するかわかりません。ご不明な点がありましたらお知らせください。ご協力いただきありがとうございます。

新しく改訂されたコードで編集します。今すぐ閉じてください!

<asp:TemplateField HeaderText="SubPlot" SortExpression="SubPlot">
    <EditItemTemplate>                            
        <asp:DropDownList ID="DropDownList1" runat="server" 
            DataSourceID="dsSubPlotNames" 
            DataTextField="SiteName" DataValueField="SiteID" 
            SelectedValue='<%# Bind("SiteID") %>'
        >
        </asp:DropDownList>
        <asp:SqlDataSource ID="dsSubPlotNames" runat="server" 
            ConnectionString="<%$ ConnectionStrings:WERCMTX %>" SelectCommand='exec [339_PPM].usp_SubPlotNames_Select null, @100mPlotName;'
            CancelSelectOnNullParameter="False">                                
            <SelectParameters>
                <asp:ControlParameter ControlID="GridView1" DefaultValue='<%# Eval("100mPlot") '
                    Name="100mPlotName" PropertyName="SelectedValue" />
             </SelectParameters>
         </asp:SqlDataSource>
     </EditItemTemplate>
          <ItemTemplate>
              <asp:Label ID="Label3" runat="server" Text='<%# Bind("SubPlot") %>'></asp:Label>
     </ItemTemplate>                        
 </asp:TemplateField>

残念ながら、Eval( "100mPlot")でこのエラーが発生します。

データバインディング式は、DataBindingイベントを持つオブジェクトでのみサポートされます。System.Web.UI.WebControls.ControlParameterにはDataBindingイベントがありません。

4

1 に答える 1

5

ラベルを付けてtextプロパティをに設定し、'<%# Eval("100mPlot") %>'データソースのコントロールパラメータを使用する必要があります。

ラベルのIDが「label1」(編集アイテムテンプレート内にある必要があります)の場合は、これを使用します

<asp:ControlParameter ControlID="label1" PropertyName="Text" Name="100mPlotSiteID" />
于 2012-05-19T01:15:37.220 に答える