FormView控件的InsertItemTemplate中3个DropDownList联动及绑定问题

在InsertItemTemplate中DropDownList联动和绑定不能同时实现,需要去掉SelectedValue=‘<%# Bind("CompanyID") %>即可实现联动,另外SqlDataSource应该放在InsertItemTemplate中。

<%@ Page Title="" Language="VB" MasterPageFile="~/Manage/Site.master" AutoEventWireup="false"
    CodeFile="PositionAdjust.aspx.vb" Inherits="Manage_PositionAdjust" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
    <asp:FormView ID="FormView1" runat="server" DataSourceID="PositionAdjustSqlDataSource"
        EnableModelValidation="True" Width="257px">
   
        <InsertItemTemplate>
            StartDate:
            <asp:TextBox ID="StartDateTextBox" runat="server" Text=‘<%# Bind("StartDate") %>‘ />
            <br />
            EndDate:
            <asp:TextBox ID="EndDateTextBox" runat="server" Text=‘<%# Bind("EndDate") %>‘ />
            <br />
            Remark:
            <asp:TextBox ID="RemarkTextBox" runat="server" Text=‘<%# Bind("Remark") %>‘ />
            <br />
            Company:
            <asp:DropDownList ID="CompanyDropDownList" runat="server" AutoPostBack="True" DataSourceID="CompanySqlDataSource"
                DataTextField="Company" DataValueField="CompanyID">
            </asp:DropDownList>
            <br />
            Depart:<asp:DropDownList ID="DepartmentDropDownList" runat="server" AutoPostBack="True"
                EnableViewState="False" DataSourceID="DepartmentSqlDataSource" DataTextField="Depart"
                DataValueField="DepartID">
            </asp:DropDownList>
            <br />
            Position:
            <asp:DropDownList ID="PositionDropDownList" runat="server" DataSourceID="PositionSqlDataSource"
                DataTextField="Position" DataValueField="PositionID">
            </asp:DropDownList>
            <br />
            <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                Text="插入" OnClick="InsertButton_Click" />
            &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False"
                CommandName="Cancel" Text="取消" />
            <br />
            <asp:SqlDataSource ID="CompanySqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:HRM_DATAConnectionString %>"
                SelectCommand="SELECT [CompanyID], [Company] FROM [tblCompany]"></asp:SqlDataSource>
            <asp:SqlDataSource ID="DepartmentSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:HRM_DATAConnectionString %>"
                SelectCommand="SELECT [DepartID], [Depart], [CompanyID] FROM [tblDepart] WHERE ([CompanyID] = @CompanyID)">
                <SelectParameters>
                    <asp:ControlParameter ControlID="CompanyDropDownList" Name="CompanyID" PropertyName="SelectedValue"
                        Type="Int32" />
                </SelectParameters>
            </asp:SqlDataSource>
            <asp:SqlDataSource ID="PositionSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:HRM_DATAConnectionString %>"
                SelectCommand="SELECT [PositionID], [Position], [DepartID] FROM [tblPosition] WHERE ([DepartID] = @DepartID)">
                <SelectParameters>
                    <asp:ControlParameter ControlID="DepartmentDropDownList" Name="DepartID" PropertyName="SelectedValue"
                        Type="Int32" />
                </SelectParameters>
            </asp:SqlDataSource>
        </InsertItemTemplate>
        <ItemTemplate>
            StartDate:
            <asp:Label ID="StartDateLabel" runat="server" Text=‘<%# Bind("StartDate") %>‘ />
            <br />
            EndDate:
            <asp:Label ID="EndDateLabel" runat="server" Text=‘<%# Bind("EndDate") %>‘ />
            <br />
            Remark:
            <asp:Label ID="RemarkLabel" runat="server" Text=‘<%# Bind("Remark") %>‘ />
            <br />
            Company:
            <asp:Label ID="CompanyLabel" runat="server" Text=‘<%# Bind("Company") %>‘ />
            <br />
            Depart:
            <asp:Label ID="DepartLabel" runat="server" Text=‘<%# Bind("Depart") %>‘ />
            <br />
            Position:
            <asp:Label ID="PositionLabel" runat="server" Text=‘<%# Bind("Position") %>‘ />
            <br />
            <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
                Text="编辑" />
            &nbsp;<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete"
                Text="***" />
            &nbsp;<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
                Text="新建" />
        </ItemTemplate>
    </asp:FormView>
    <asp:SqlDataSource ID="PositionAdjustSqlDataSource" runat="server" ConflictDetection="CompareAllValues"
              ConnectionString="<%$ ConnectionStrings:HRM_DATAConnectionString %>" ProviderName="<%$ ConnectionStrings:HRM_DATAConnectionString.ProviderName %>"
        InsertCommand="INSERT INTO tblPositionAdjust(StaffID, StartDate, EndDate, CompanyID, DepartID, PositionID, Remark) VALUES (@StaffID,@StartDate,@EndDate,@CompanyID,@DepartID,@PositionID,@Remark)">
     
        <InsertParameters>
            <asp:SessionParameter Name="StaffID" SessionField="strStaffID" Type="String" />
            <asp:Parameter Name="StartDate" Type="DateTime" />
            <asp:Parameter Name="EndDate" Type="DateTime" />
            <asp:Parameter Name="CompanyID" />
            <asp:Parameter Name="DepartID" Type="Int32" />
            <asp:Parameter Name="PositionID" Type="Int32" />
            <asp:Parameter Name="Remark" Type="String" />
            <asp:Parameter Name="StafffID" />
        </InsertParameters>
        <SelectParameters>
            <asp:QueryStringParameter Name="Sn" QueryStringField="Sn" />
        </SelectParameters>
    
    </asp:SqlDataSource>
</asp:Content>

‘后台代码中绑定
    Protected Sub FormView1_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertEventArgs) Handles FormView1.ItemInserting
        PositionAdjustSqlDataSource.InsertParameters("StaffID").DefaultValue = Session("strStaffID")
        PositionAdjustSqlDataSource.InsertParameters("CompanyID").DefaultValue = CType(FormView1.FindControl("CompanyDropDownList"), DropDownList).SelectedValue
        PositionAdjustSqlDataSource.InsertParameters("DepartID").DefaultValue = CType(FormView1.FindControl("DepartmentDropDownList"), DropDownList).SelectedValue
        PositionAdjustSqlDataSource.InsertParameters("PositionID").DefaultValue = CType(FormView1.FindControl("PositionDropDownList"), DropDownList).SelectedValue
    End Sub

FormView控件的InsertItemTemplate中3个DropDownList联动及绑定问题,布布扣,bubuko.com

时间: 2024-12-26 04:00:38

FormView控件的InsertItemTemplate中3个DropDownList联动及绑定问题的相关文章

【转载】OLE控件在Direct3D中的渲染方法

原文:OLE控件在Direct3D中的渲染方法 Windows上的图形绘制是基于GDI的, 而Direct3D并不是, 所以, 要在3D窗口中显示一些Windows中的控件会有很多问题 那么, 有什么办法让GDI绘制的内容在3D中显示出来?反正都是图像, 总有办法实现的嘛! 前段时间在研究浏览器在游戏中的嵌入, 基本的思路就是在后台打开一个浏览窗口, 然后把它显示的内容拷贝到一张纹理上, 再把纹理在D3D中绘制出来, 至于事件处理就要另做文章了. 所以, 其它的Windows里的GDI绘制的东西

fileupload控件在ajax中无法使用

google得到的方法: 1.http://geekswithblogs.net/ranganh/archive/2008/04/01/file-upload-in-updatepanel-asp.net-ajax.aspx There is a better way of doing it with Ajax Control Toolkit version 3.0.30930 which works with .NET 3.5 SP1 and Visual Studio 2008 SP1. 

Android得到控件在屏幕中的坐标

getLocationOnScreen ,计算该视图在全局坐标系中的x,y值,(注意这个值是要从屏幕顶端算起,也就是索包括了通知栏的高度)//获取在当前屏幕内的绝对坐标 getLocationInWindow ,计算该视图在它所在的widnow的坐标x,y值,//获取在整个窗口内的绝对坐标 (不是很理解= =.) getLeft , getTop, getBottom, getRight, 这一组是获取相对在它父亲里的坐标 如果在Activity的OnCreate()事件输出那些参数,是全为0,

自定义控件时-添加多个控件到一组中

dmwidgetinterface.h 1 #ifndef _DM_WIDGET_INTERFACE_H_ 2 #define _DM_WIDGET_INTERFACE_H_ 3 4 5 #include <QDesignerCustomWidgetInterface> 6 7 8 // DM自定义控件 9 class DmWidgetInterface : public QObject, public QDesignerCustomWidgetInterface 10 { 11 Q_OBJE

在第三方控件 super Grid 中想要删除选中的行

代码: DialogResult result = MessageBox.Show("确定移除选中词吗?", "移除选中",MessageBoxButtons.YesNo,MessageBoxIcon.Information); if (result == DialogResult.Yes) { SelectedElementCollection grid = SuperGrid.PrimaryGrid.GetSelectedRows(); foreach (Gri

GridView控件RowDataBound事件中获取列字段值的几种途径 !!!

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes.Add("onclick", "javascript:alert('当前ID为:" +DataBinder.Eval(e.Row.DataItem,"CID"

Android Studio中Button等控件的Text中字符串默认大写的解决方法

初学Android的时候,在Android Studio中xml里面添加一个Button.EditText等控件后,它的Text总是会显示大写,即使你输入的字符串是小写也不行,控制字符串大小写的属性是android:textAllCaps, 最后查看了一下Themes.xml文件,找到了一些端倪,发现在设置样式的时候,默认是把所有的字符串显示大写true. 如图,是从android的Style.xml中的截图,   [解决办法] 1. 把xml中你不想大写的控件添加一行 android:text

配置ActiveX控件在网页中下载安装

先检查客户端浏览器是否安装了ActiveX控件,如果没有安装ActiveX,就需要先给浏览器提示下载并允许安装.否则就直接使用该ActiveX控件.我们可以使用CodeBase来满足我们的要求:下面是一个html的调用: <object classid="clsid:636B8CE1-7512-464C-B63C-FC75BDCA21DB" codebase="Charles2008ActiveX/setup.exe#version=1,0,0,0" widt

Android 获得控件在屏幕中的坐标 - 总结

Android坐标原点为左上角,如果是某个View,那么就以该矩阵的左上角为原点 1.绝对坐标 Location int[] location = new int[2] ; view.getLocationInWindow(location); //获取在当前窗口内的绝对坐标,含toolBar view.getLocationOnScreen(location); //获取在整个屏幕内的绝对坐标,含statusBar // location [0]--->x坐标,location [1]--->