搞了好几天都不行,急死了,数据邦定控件中的模板到底怎么回事?

lovcal 2006-08-25 02:35:02
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)
...全文
137 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
lovcal 2006-08-25
  • 打赏
  • 举报
回复
我是数据邦定的,没什么代码
lindping 2006-08-25
  • 打赏
  • 举报
回复
原来是。net2005呀,不好意思不熟。
不过我还是看得不太明白,你的控制联动的代码呢?

难道vs2005里面不需要写后台代码?
第一个dropdownlist 的
SelectedValue='<%# Bind("sMeiChang_no") %>' 一旦更改,就能自动触发

DataSourceID="ObjectDataSource_BangFang" 也发生更改吗?
lovcal 2006-08-25
  • 打赏
  • 举报
回复
写错了,应该是这样:

<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>
lovcal 2006-08-25
  • 打赏
  • 举报
回复
就是其中的这两行
===========================================================
<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>
lovcal 2006-08-25
  • 打赏
  • 举报
回复
<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>
lindping 2006-08-25
  • 打赏
  • 举报
回复
你的联动代码帖来看看
lovcal 2006-08-25
  • 打赏
  • 举报
回复
不行
zzz22333 2006-08-25
  • 打赏
  • 举报
回复
试试把控件删了,再加个新的重新绑定

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧