我使用gridview編輯/刪除。當用戶點擊「編輯」時,我需要將一個列(100mPLot)的值傳遞給一個數據源,該數據源將填充另一列(SubPlot)的下拉列表。這是我有:從gridview傳遞參數到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="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.
我該如何解決這個問題?謝謝,
編輯:
我把它給後面的代碼,並創建包含前一列的值隱藏標籤標記後,處理它的RowDataBound。
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && (e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit)
{
Label lbl100mPlot = (Label)e.Row.FindControl("lbl100mPlot");
SqlDataSource dsPlotNames = (SqlDataSource)e.Row.FindControl("dsSubPlotNames");
dsPlotNames.SelectParameters.Clear();
dsPlotNames.SelectParameters.Add("100mPlotSiteID", null);
dsPlotNames.SelectParameters.Add("100mPlotName", lbl100mPlot.Text);
}
}
我的下一個問題是這樣的錯誤:
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
Exception Details: System.InvalidOperationException: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
Source Error:
[No relevant source lines]
我不知道是什麼導致了它。
謝謝,我把它移到代碼後面,並能解決參數傳遞問題。但現在我面臨着一個不同的問題。 – dam