GridView和DetailsView配合使用遇到的问题
尝试做了个GridView和DetailsView联动的页面,点击GridView的“选取”,就可以出现DetailsView的界面:下面是代码,我遇到了两个问题:
问题1:我修改了DetailsView后,GridView的数据不能即时显示更新后的效果,也就是DetailsView上修改了数据,GridView还是显示老数据,要下一次打开GridView才能显示更新后的效果。
问题2:DetailsView每次都是从页面的顶部出现,实在不方便。我想改造成能在当前页面弹出一个DetailsView窗口,当我在这个DetailsView窗口更新完数据后,点击DetailsView最下面的“更新”或“删除”键,便能保存结果并关闭DetailsView窗口。这个这个功能对于我来说太难了,完全不知道从何入手!
我是菜鸟,请各位帮忙看看!谢谢
--------------------------前台代码--------------------------
--------------------编程问答-------------------- 你如果想要实现在当前页面弹出一个DetailsView窗口, 要用js实现,或者根据情况显示出一个div, 放置一个detailsview在div中,根据情况显示出来,或者使用window.open打开一个新窗口,控制它的大小和显示位置 --------------------编程问答-------------------- 问题1:给DetailsView增加事件
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="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">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataKeyNames="EmployeeID" DataSourceID="SqlDataSource_DetaisView" Height="50px"
Width="125px">
<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>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="EmployeeID" DataSourceID="SqlDataSource_GridView">
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="btn_Select" 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="LastName" HeaderText="LastName"
SortExpression="LastName" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource_DetaisView" 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="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>
<asp:SqlDataSource ID="SqlDataSource_GridView" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [EmployeeID], [LastName] FROM [Employees]">
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
protected void DetailsView1_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
{
GridView1.DataBind();
}
问题2:下面有相关视频教程,让你的问题得到彻底解决。
http://www.verycd.com/topics/2821314/ --------------------编程问答--------------------
能说下具体是哪个视频文件里啊?
补充:.NET技术 , ASP.NET