C# 将参数传递给';s绑定到gridview更新中的dropdownlist
我有一个具有许多列的可编辑gridview。其中两个是100mPlot和SubPlot。子地块不是唯一的(1A、1B、1C和1D),但100mPlot+子地块构成一组唯一的值 当用户单击“编辑”时,他们将在“子批次”列中看到一个下拉列表。此列表需要基于100mPlot的值。因此,为了显示子批的正确值,我需要将100mPlot列中的值作为参数传递给将绑定到子批dropdownlist的sqldatasource。我该怎么办C# 将参数传递给';s绑定到gridview更新中的dropdownlist,c#,asp.net,gridview,drop-down-menu,C#,Asp.net,Gridview,Drop Down Menu,我有一个具有许多列的可编辑gridview。其中两个是100mPlot和SubPlot。子地块不是唯一的(1A、1B、1C和1D),但100mPlot+子地块构成一组唯一的值 当用户单击“编辑”时,他们将在“子批次”列中看到一个下拉列表。此列表需要基于100mPlot的值。因此,为了显示子批的正确值,我需要将100mPlot列中的值作为参数传递给将绑定到子批dropdownlist的sqldatasource。我该怎么办 <asp:BoundField DataField="100mPlo
<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”)中遇到了这个错误:
只有具有数据绑定事件的对象才支持数据绑定表达式。System.Web.UI.WebControl.ControlParameter没有数据绑定事件
您需要放置一个标签并将text属性设置为
'
,并在数据源中使用控件参数
如果标签的id为“label1”(必须位于编辑项模板内),则使用此
<asp:ControlParameter ControlID="label1" PropertyName="Text" Name="100mPlotSiteID" />
您需要放置一个标签,并将text属性设置为
'
,并在数据源中使用控制参数
如果标签的id为“label1”(必须位于编辑项模板内),则使用此
<asp:ControlParameter ControlID="label1" PropertyName="Text" Name="100mPlotSiteID" />
这样做会产生以下错误:只有具有数据绑定事件的对象才支持数据绑定表达式。System.Web.UI.WebControls.Parameter没有数据绑定事件。然后,您需要放置一个标签,并将te text属性设置为'
,并在数据源中使用一个控制参数。您能进一步澄清一下吗?标签会放在哪里?在数据源中,是否将控制参数配置为指向此标签?谢谢。如果标签的id为“label1”(必须在编辑项模板内),则使用此
我已更新了答案。如果有效,请将其标记为答案。这样做会导致以下错误:只有具有数据绑定事件的对象才支持数据绑定表达式。System.Web.UI.WebControls.Parameter没有数据绑定事件。然后,您需要放置一个标签,并将te text属性设置为'
,并在数据源中使用一个控制参数。您能进一步澄清一下吗?标签会放在哪里?在数据源中,是否将控制参数配置为指向此标签?谢谢。如果标签的id为“label1”(必须在编辑项目模板内),则使用此
我已更新答案。如果有效,请将其标记为答案。