我有一个包含许多列的可编辑gridview。其中两个是100mPlot和SubPlot。 SubPlot的不是唯一的(1A,1B,1C和1D),但100mPlot + SubPlot创建一组唯一的值。将参数传递给绑定到gridview更新中的下拉列表的sqldatasource
当用户点击“编辑”时,他们将在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 expressions are only supported on objects that have a DataBinding event. System.Web.UI.WebControls.ControlParameter does not have a DataBinding event.
这样做,让我这个错误: 数据绑定表达式仅支持在具有DataBinding事件的对象。 System.Web.UI.WebControls.Parameter没有DataBinding事件。 – dam
然后,您需要放置一个标签并将te文本属性设置为''<%#Eval(“100mPlot”)%>''并在数据源中使用控制参数。 –
你能澄清一点吗?标签去哪里?在数据源中,是否将控制参数配置为指向此标签?谢谢。 – dam