gpt4 book ai didi

c# - 将参数传递给绑定(bind)到 gridview 更新中的下拉列表的 sqldatasource

转载 作者:太空宇宙 更新时间:2023-11-03 20:25:55 25 4
gpt4 key购买 nike

我有一个包含许多列的可编辑 GridView 。其中两个是 100mPlot 和 SubPlot。 SubPlot 不是唯一的(1A、1B、1C 和 1D),但 100mPlot + SubPlot 构成了一组唯一的值。

当用户点击“编辑”时,他们将在“子图”列中看到一个下拉列表。此列表需要基于 100mPlot 的值。因此,为了显示 SubPlot 的正确值,我需要将 100mPlot 列的值作为参数传递给将绑定(bind)到 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 expressions are only supported on objects that have a DataBinding event. System.Web.UI.WebControls.ControlParameter does not have a DataBinding event.

最佳答案

您需要放置一个标签并将文本属性设置为'<%# Eval("100mPlot") %>'并在数据源中使用控制参数。

如果标签的 id 是“label1”(必须在编辑项模板内)则使用此

<asp:ControlParameter ControlID="label1" PropertyName="Text" Name="100mPlotSiteID" />

关于c# - 将参数传递给绑定(bind)到 gridview 更新中的下拉列表的 sqldatasource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10661493/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com