急,在FormView中用程序绑定了DropDownList,数据无法正常插入!!!
<asp:FormView ID="frmCarInsert" runat="server" DefaultMode="Insert" CssClass="fromview"><InsertItemTemplate>
<th>使用部门:</th>
<td>
<asp:TextBox ID="departMentIDTextBox" runat="server"
Text='<%# Bind("departMentID")%>'ValidationGroup="edit" />
</td>
....略,这样可以插入将使用部门改为
<th>使用部门:</th>
<td>
<asp:DropDownList ID="ddlDepartMentInsert" runat="server"
AppendDataBoundItems="True" ValidationGroup="insert" >
<asp:ListItem Value="-1" >请选择部门</asp:ListItem>
</asp:DropDownList>
</td>
而这里的ddlDepartMentInsert是后台代码编程做绑定,改成这样就无法插入数据,没有提示。
我感觉是缺少了 <%# Bind("departMentID")%>
于是改成<asp:DropDownList ID="ddlDepartMentInsert" runat="server" AppendDataBoundItems="True" ValidationGroup="insert" SelectedValue='<%# Bind("departMentID") %> '>
<asp:ListItem Value="-1" >请选择部门</asp:ListItem>
</asp:DropDownList>
晕,提示
Eval()、XPath() 和 Bind() 这类数据绑定方法只能在数据绑定控件的上下文中使用。
--------------------编程问答-------------------- up --------------------编程问答-------------------- 如果楼主打算用自己编程操作DropDownList而不是使用数据源控件,在前台设置Bind()这种语法是没有意义的 --------------------编程问答--------------------
改成:
<asp:FormView ID="frmCarInsert" runat="server" DefaultMode="Insert" CssClass="fromview">
<InsertItemTemplate>
<th>使用部门: </th>
<td>
<asp:TextBox ID="departMentIDTextBox" runat="server"
Text=' <%# Eval("departMentID")%>'ValidationGroup="edit" />
</td> --------------------编程问答-------------------- 看看 --------------------编程问答-------------------- 是这样的
表结构如下
oils(油种) states(状态) companies单位 departCategory单位分类 departMents部门表
----------- ------------- ------------ -------------------- -------------------
id id id id id
oilsName stateName companyName departCategoryName departMentName
companyID departCategoryID
cars 车http://i1.sinaimg.cn/ty/olympic08/maxthon/0806/maxthon_zty_s001.jpg
-----------
id
carsName
oilID (油外键)
stateID (状态外键)
departMentID (部门外键)
注意上面的 ( companies单位 departCategory单位分类 departMents部门表 )是级联关系
同时也注意cars车表中的(oilID 和stateID,直接引用,fromView中用dropDown好绑定,)现在要用dropDown根据formview外面的一个dropDownList(它绑定了单位),根据单位直接列出部门,跳过departCategory单位分类,直接列出部门,
FormView用来插入car记录,我想用dropdownlist绑定通过单位选出来的部门,如何做?
--------------------编程问答-------------------- 是这样的
表结构如下
oils(油种) states(状态) companies单位 departCategory单位分类 departMents部门表
----------- ------------- ------------ -------------------- -------------------
id id id id id
oilsName stateName companyName departCategoryName departMentName
companyID departCategoryID
cars 车
-----------
id
carsName
oilID (油外键)
stateID (状态外键)
departMentID (部门外键)
注意上面的 ( companies单位 departCategory单位分类 departMents部门表 )是级联关系
同时也注意cars车表中的(oilID 和stateID,直接引用,fromView中用dropDown好绑定,)现在要用dropDown根据formview外面的一个 dropDownList(它绑定了单位),根据单位直接列出部门,跳过departCategory单位分类,直接列出部门,
FormView用来插入car记录,我想用dropdownlist绑定通过单位选出来的部门,如何做?
补充:.NET技术 , ASP.NET