FormView
我在其EditTemplate中放了2个DropDownList也就是希望在编辑状态下操作时,对于下拉框1中的值改变时,Postback刷新一下下拉框2中的可选项值,也就是联动但总是提示如下错误:=========================================================
用户代码未处理 System.InvalidOperationException
  Message="Eval()、XPath() 和 Bind() 这类数据绑定方法只能在数据绑定控件的上下文中使用。"
  Source="System.Web"
  StackTrace:
       在 System.Web.UI.Page.GetDataItem()
       在 System.Web.UI.TemplateControl.Eval(String expression)
       在 ASP.order_ordermain_aspx.__DataBinding__control53(Object sender, EventArgs e) 位置 d:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\OCRS_NET\Order\OrderMain.aspx:行号 167
       在 System.Web.UI.Control.OnDataBinding(EventArgs e)
       在 System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e)
       在 System.Web.UI.WebControls.ListControl.PerformSelect()
       在 System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
       在 System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound()
       在 System.Web.UI.WebControls.BaseDataBoundControl.OnPreRender(EventArgs e)
       在 System.Web.UI.WebControls.ListControl.OnPreRender(EventArgs e)
       在 System.Web.UI.Control.PreRenderRecursiveInternal()
       在 System.Web.UI.Control.PreRenderRecursiveInternal()
       在 System.Web.UI.Control.PreRenderRecursiveInternal()
       在 System.Web.UI.Control.PreRenderRecursiveInternal()
       在 System.Web.UI.Control.PreRenderRecursiveInternal()
       在 System.Web.UI.Control.PreRenderRecursiveInternal()
       在 System.Web.UI.Control.PreRenderRecursiveInternal()
       在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

解决方案 »

  1.   

    <EditItemTemplate>
          <p align="justify">
              <table>
                  <tr>
                      <td align="right" style="height: 26px">
                          <asp:Label ID="Label9" runat="server" Text="订单编号:"></asp:Label></td>
                      <td align="left" style="height: 26px">
                          <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("sOrder_no") %>' Width="185px" ReadOnly="True"></asp:TextBox></td>
                      <td align="right" style="height: 26px">
                          <asp:Label ID="Label10" runat="server" Text="购买总数量:"></asp:Label></td>
                      <td align="left" style="height: 26px; width: 158px;">
                          <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("fTotalCount") %>' Width="100px" ReadOnly="True"></asp:TextBox></td>
                  </tr>
                  <tr>
                      <td align="right" style="height: 26px">
                          <asp:Label ID="Label2" runat="server" Text="销售单位:"></asp:Label></td>
                      <td align="left" style="height: 26px">
                          <asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("sCompany_no") %>' Width="185px" ReadOnly="True"></asp:TextBox></td>
                      <td align="right" style="height: 26px">
                          <asp:Label ID="Label5" runat="server" Text="单据方式:" Width="97px"></asp:Label></td>
                      <td align="left" style="height: 26px; width: 158px;">
                          <asp:DropDownList ID="ddlBillCL" runat="server" Width="104px" DataSourceID="ObjectDataSource_BillClass" DataTextField="sBillCLName" DataValueField="sBillCLNo">
                          </asp:DropDownList></td>
                  </tr>
                  <tr>
                      <td align="right" style="height: 26px">
                          <asp:Label ID="Label1" runat="server" Text="客商名称:" Width="97px"></asp:Label></td>
                      <td align="left" style="height: 26px">
                          <asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("sCustb_name") %>' Width="186px" ReadOnly="True"></asp:TextBox></td>
                      <td align="right" style="height: 26px">
                          <asp:Label ID="Label13" runat="server" Text="结算类型:" Width="97px"></asp:Label></td>
                      <td align="left" style="height: 26px; width: 158px;">
                          <asp:DropDownList ID="ddlJSType" runat="server" Width="104px">
                              <asp:ListItem Value="1">按吨数</asp:ListItem>
                              <asp:ListItem Value="0">按金额</asp:ListItem>
                          </asp:DropDownList></td>  
                  </tr>
                  <tr>
                      <td align="right" style="height: 24px">
                          <asp:Label ID="Label3" runat="server" Text="场地名称:"></asp:Label></td>
                      <td align="left" style="height: 24px">
                          <asp:DropDownList ID="ddlMeiChang" runat="server" Width="190px" DataSourceID="ObjectDataSource_MeiChang" DataTextField="sMC_name" DataValueField="sMeiChang_no" AutoPostBack="True" SelectedValue='<%# Bind("sMeiChang_no") %>'>
                          </asp:DropDownList></td>
                      <td align="right" style="height: 24px">
                          <asp:Label ID="Label4" runat="server" Text="磅房名称:" Width="97px"></asp:Label></td>
                      <td align="left" style="height: 24px; width: 158px;">
                          <asp:DropDownList ID="ddlBangfang" runat="server" Width="105px" DataSourceID="ObjectDataSource_BangFang" DataTextField="sBF_name" DataValueField="sBangFang_no">
                          </asp:DropDownList>
                          <asp:TextBox ID="tbBangFang" runat="server" Text='<%# Bind("sBangFang_no") %>' Visible="False"></asp:TextBox></td>
                  </tr>
                  <tr>
                      <td align="right" style="height: 24px">
                          <asp:Label ID="Label6" runat="server" Text="工作流:" Width="78px"></asp:Label></td>
                      <td align="left" style="height: 24px">
                          <asp:DropDownList ID="ddlWorkFlow1" runat="server" Width="188px" DataSourceID="ObjectDataSource_WorkFlow" DataTextField="sWorkFlow_name" DataValueField="sWorkFlow_no" SelectedValue='<%# Bind("sWorkFlow_name") %>'>
                          </asp:DropDownList></td>
                      <td align="right" style="height: 24px">
                          <asp:Label ID="Label7" runat="server" Text="转零售工作流:" Width="160px"></asp:Label></td>
                      <td align="left" style="height: 24px; width: 158px;">
                          <asp:DropDownList ID="ddlWorkFlow2" runat="server" Width="104px" DataSourceID="ObjectDataSource_WorkFlow" DataTextField="sWorkFlow_name" DataValueField="sWorkFlow_no" SelectedValue='<%# Bind("sWorkFlow_name2") %>'>
                          </asp:DropDownList></td>
                  </tr>
                  <tr>
                      <td align="right" style="height: 26px">
                          <asp:Label ID="Label11" runat="server" Text="建单时间:" Width="97px"></asp:Label></td>
                      <td align="left" style="height: 26px">
                          <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("dCreateTime") %>' Width="180px" ReadOnly="True"></asp:TextBox></td>
                      <td align="right" style="height: 26px">
                          <asp:Label ID="Label8" runat="server" Text="状态:" Width="97px"></asp:Label></td>
                      <td align="left" style="height: 26px; width: 158px;">
                          <asp:TextBox ID="TextBox4" runat="server" Width="100px" ReadOnly="True" Text='<%# Bind("sBillStatus") %>'></asp:TextBox></td>
                  </tr>
              </table>
          </p>
          <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
              Text="更新"></asp:LinkButton>
          <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
              Text="取消"></asp:LinkButton>
      </EditItemTemplate>
      

  2.   

    就是其中的这两行
    ===========================================================
    <tr>
                      <td align="right" style="height: 24px">
                          <asp:Label ID="Label3" runat="server" Text="场地名称:"></asp:Label></td>
                      <td align="left" style="height: 24px">
                          <asp:DropDownList ID="ddlMeiChang" runat="server" Width="190px" DataSourceID="ObjectDataSource_MeiChang" DataTextField="sMC_name" DataValueField="sMeiChang_no" AutoPostBack="True" SelectedValue='<%# Bind("sMeiChang_no") %>'>
                          </asp:DropDownList></td>
                      <td align="right" style="height: 24px">
                          <asp:Label ID="Label4" runat="server" Text="磅房名称:" Width="97px"></asp:Label></td>
                      <td align="left" style="height: 24px; width: 158px;">
                          <asp:DropDownList ID="ddlBangfang" runat="server" Width="105px" DataSourceID="ObjectDataSource_BangFang" DataTextField="sBF_name" DataValueField="sBangFang_no">
                          </asp:DropDownList>
                          <asp:TextBox ID="tbBangFang" runat="server" Text='<%# Bind("sBangFang_no") %>' Visible="False"></asp:TextBox></td>
                  </tr>
      

  3.   

    写错了,应该是这样:<tr>
                      <td align="right" style="height: 24px">
                          <asp:Label ID="Label3" runat="server" Text="场地名称:"></asp:Label></td>
                      <td align="left" style="height: 24px">
                          <asp:DropDownList ID="ddlMeiChang" runat="server" Width="190px" DataSourceID="ObjectDataSource_MeiChang" DataTextField="sMC_name" DataValueField="sMeiChang_no" AutoPostBack="True" SelectedValue='<%# Bind("sMeiChang_no") %>'>
                          </asp:DropDownList></td>
                      <td align="right" style="height: 24px">
                          <asp:Label ID="Label4" runat="server" Text="磅房名称:" Width="97px"></asp:Label></td>
                      <td align="left" style="height: 24px; width: 158px;">
                          <asp:DropDownList ID="ddlBangfang" runat="server" Width="105px" DataSourceID="ObjectDataSource_BangFang" DataTextField="sBF_name" DataValueField="sBangFang_no" SelectedValue='<%# Bind("sBangFang_no") %>'>
                          </asp:DropDownList>
                      </td>
                  </tr>
      

  4.   

    原来是。net2005呀,不好意思不熟。 
    不过我还是看得不太明白,你的控制联动的代码呢?难道vs2005里面不需要写后台代码?
    第一个dropdownlist 的
    SelectedValue='<%# Bind("sMeiChang_no") %>' 一旦更改,就能自动触发DataSourceID="ObjectDataSource_BangFang" 也发生更改吗?