none
为了更美观实用!如何把这个DetailsView放到弹出的窗口中? RRS feed

  • 问题

  •     今天找了不少资料,终于做出了GridView和DetailsView配合使用的界面,运行正常。效果是:点击GridView的“选取”,就能在界面的左上角弹出一个DetailsView,更新、删除等功能正常且GridView的内容也能同步更新。

    我想做得更科学一些,想把DetailsView窗口做成一个在界面中间弹出来的效果。费了老大的劲,做出来的效果如图。要怎么样做成一个能浮动在界面上一层的弹出窗口啊?就像弹出广告的效果一样!

    ------------------------图1-------------------------------


    -----------------------------前台代码------------------------------

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Try_Default2" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <script language="javascript">
    //******************************************************
    function controlDiv(DivID,divCase){
    var divs=document.getElementById(DivID);
    var v_left=(document.body.clientWidth-300)/2 + document.body.scrollLeft; //divs.clientWidth
    var v_top=(document.body.clientHeight-divs.clientHeight)/2 + document.body.scrollTop;
    if(divCase==1){
    divs.style.left=v_left+'px';
    divs.style.top=v_top+'px';
    divs.style.display="block"; //显示DIV
    }else if(divCase==2)
    divs.style.display="none"; //屏蔽DIV
    else
       divs.innerHTML=divCase; //输出HTML文本到DIV
    }
    //******************************************************
    </script>
    
    
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        
        <div align="center">
    <p>&nbsp;</p>
    <%--<p><a href="#" onclick="controlDiv('msgDiv',1)">点击弹出</a></p>--%>
    </div>
    <%--<div align="center"><a href="#" onclick="controlDiv('msgDiv',1)">点击弹出</a></div>--%>
    <div id="msgDiv">
    <%--<h1><span>[<a href="#" onclick="controlDiv('msgDiv',2)">关闭</a>]</span>弹出窗口</h1>--%>
        <div align="center"><br />
        <asp:DetailsView ID="DetailsView_Details1" runat="server" Height="50px" 
                Width="125px" AutoGenerateRows="False" DataKeyNames="EmployeeID" 
                DataSourceID="SqlDataSource_Details1" 
                onitemdeleted="DetailsView_Details1_ItemDeleted" 
                oniteminserted="DetailsView_Details1_ItemInserted" 
                onitemupdated="DetailsView_Details1_ItemUpdated" >
                <Fields>
                    <asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID" 
                        InsertVisible="False" ReadOnly="True" SortExpression="EmployeeID" />
                    <asp:BoundField DataField="LastName" HeaderText="LastName" 
                        SortExpression="LastName" />
                    <asp:BoundField DataField="FirstName" HeaderText="FirstName" 
                        SortExpression="FirstName" />
                    <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" 
                        ShowInsertButton="True" />
                </Fields>
            </asp:DetailsView><br />
            <h1 style="font-size: small"><span>[<a href="#" onclick="controlDiv('msgDiv',2)">关闭</a>]</span>弹出窗口</h1>
        </div>
    </div>
        
        <div>
            
        
        </div>
        <div>
        
            <asp:GridView ID="GridView_Gridview1" runat="server" 
                AutoGenerateColumns="False" DataKeyNames="EmployeeID" 
                DataSourceID="SqlDataSource_Gridview1">
                <Columns>
                    <asp:TemplateField ShowHeader="False">
                        <ItemTemplate>
                            <asp:LinkButton ID="LinkButton_Selected" runat="server" CausesValidation="False" 
                                CommandName="Select" Text="选择"></asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID" 
                        InsertVisible="False" ReadOnly="True" SortExpression="EmployeeID" />
                    <asp:BoundField DataField="FirstName" HeaderText="FirstName" 
                        SortExpression="FirstName" />
                    <asp:BoundField DataField="LastName" HeaderText="LastName" 
                        SortExpression="LastName" />
                    <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                    <asp:BoundField DataField="TitleOfCourtesy" HeaderText="TitleOfCourtesy" 
                        SortExpression="TitleOfCourtesy" />
                </Columns>
            </asp:GridView>
               
        </div>
        <div>
        
        
            <asp:SqlDataSource ID="SqlDataSource_Gridview1" runat="server" 
                ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" 
                
                SelectCommand="SELECT [EmployeeID], [FirstName], [LastName], [Title], [TitleOfCourtesy] FROM [Employees]">
            </asp:SqlDataSource>
        
        
            <asp:SqlDataSource ID="SqlDataSource_Details1" runat="server" 
                ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" 
                DeleteCommand="DELETE FROM [Employees] WHERE [EmployeeID] = @EmployeeID" 
                InsertCommand="INSERT INTO [Employees] ([LastName], [FirstName]) VALUES (@LastName, @FirstName)" 
                SelectCommand="SELECT [EmployeeID], [LastName], [FirstName] FROM [Employees] WHERE [EmployeeID] = @EmployeeID" 
                
                UpdateCommand="UPDATE [Employees] SET [LastName] = @LastName, [FirstName] = @FirstName WHERE [EmployeeID] = @EmployeeID">
                <SelectParameters>
                    <asp:ControlParameter ControlID="GridView_Gridview1" Name="EmployeeID" 
                        PropertyName="SelectedValue" />
                </SelectParameters>
                <DeleteParameters>
                    <asp:Parameter Name="EmployeeID" Type="Int32" />
                </DeleteParameters>
                <UpdateParameters>
                    <asp:Parameter Name="LastName" Type="String" />
                    <asp:Parameter Name="FirstName" Type="String" />
                    <asp:Parameter Name="EmployeeID" Type="Int32" />
                </UpdateParameters>
                <InsertParameters>
                    <asp:Parameter Name="LastName" Type="String" />
                    <asp:Parameter Name="FirstName" Type="String" />
                </InsertParameters>
            </asp:SqlDataSource>
        
        
        </div>
        </form>
    </body>
    </html>


    ---------------------------后台代码----------------------------

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class Try_Default2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        protected void DetailsView_Details1_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
        {
            GridView_Gridview1.DataBind();
        }
        protected void DetailsView_Details1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
        {
            GridView_Gridview1.DataBind();
        }
        protected void DetailsView_Details1_ItemDeleted(object sender, DetailsViewDeletedEventArgs e)
        {
            GridView_Gridview1.DataBind();
        }
    }

       

    C# 菜鸟中的雏鸟!提的问题也许很幼稚,但我是认真的。希望看在党国的面子上拉兄弟一把!



    2013年4月18日 7:49

答案