1.翻页的问题:翻页时要保存控件的选择状态,用Datagrid怎么解决?用数组还是其他的?
2.如果有人答了一部分想保存,如何保存?想再答时怎么提取?(有翻页的)
10 个解决方案
#1
第一个问题的答案,这里看,跨页面多选择
http://dotnet.aspx.cc/ShowDetail.aspx?id=F43AF9A5-2C2E-4AA6-E976-21E9569F5A8A
http://dotnet.aspx.cc/ShowDetail.aspx?id=F43AF9A5-2C2E-4AA6-E976-21E9569F5A8A
#2
up
:)
:)
#3
页面少的话用panel做翻页偶感觉也不错
#4
up
#5
panel做翻页
#6
用panel做翻页
或去【孟宪会之精彩世界】
http://dotnet.aspx.cc/ShowDetail.aspx?id=F43AF9A5-2C2E-4AA6-E976-21E9569F5A8A
或去【孟宪会之精彩世界】
http://dotnet.aspx.cc/ShowDetail.aspx?id=F43AF9A5-2C2E-4AA6-E976-21E9569F5A8A
#7
为了方便起见,我们连接SQL Server 2000的NorthWind数据库的Orders表,从数据库里得到此表的数据视图。利用DataGrid的SortCommand事件实现排序。用一个模板列加上CheckBox控件实现选择。可用DataGrid的属性生成器的“分页”选项或者自己修改HTML实现分页。
HTML:
l 添加一个DataGrid,命名为dgOrder。
l 添加了一个模板列,模板列里放一个名为Cb的CheckBox控件。此列用来实现选择
l 为要排序的每个列加上排序表达式SortExpression。
l 利用列的DataFormatString来格式化列,象DataFormatString="{0:d}"显示日期格式。
l 设置PageSize="15"每页显示15行数据,AllowPaging="True" 为允许分页 。
整个HTML页代码:
<form id="Form1" method="post" runat="server">
<asp:datagrid id="dgOrder" runat="server" Height="515px" Width="718px" AutoGenerateColumns="False" AllowSorting="True" CellPadding="4" BorderWidth="1px" BorderColor="#A0ABEB" PageSize="15" BorderStyle="Solid" BackColor="White" GridLines="Vertical" ForeColor="Black" AllowPaging="True" ShowFooter="True">
<SelectedItemStyle ForeColor="White" BackColor="Black"></SelectedItemStyle>
<AlternatingItemStyle BackColor="#EEEEEE"></AlternatingItemStyle>
<HeaderStyle HorizontalAlign="Center" ForeColor="White" BorderColor="#6876C5" BackColor="#6876C5"></HeaderStyle>
<FooterStyle ForeColor="White" BackColor="#6876C5"></FooterStyle>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<FONT face="">
<asp:CheckBox id="Cb" runat="server"></asp:CheckBox></FONT>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="orderid" SortExpression="orderid" HeaderText="ID">
<HeaderStyle Width="180px"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="ShipCountry" SortExpression="ShipCountry" HeaderText="ShipCountry">
<HeaderStyle Width="180px"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="ShippedDate" SortExpression="ShippedDate" HeaderText="ShippedDate" DataFormatString="{0:d}">
<HeaderStyle Width="180px"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="Freight" SortExpression="Freight" HeaderText="Freight">
<HeaderStyle Width="180px"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="ShipAddress" SortExpression="ShipAddress" HeaderText="ShipAddress">
<HeaderStyle Width="480px"></HeaderStyle>
</asp:BoundColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="Black" Position="TopAndBottom" BackColor="White" Mode="NumericPages"></PagerStyle>
</asp:datagrid>
</form>
HTML:
l 添加一个DataGrid,命名为dgOrder。
l 添加了一个模板列,模板列里放一个名为Cb的CheckBox控件。此列用来实现选择
l 为要排序的每个列加上排序表达式SortExpression。
l 利用列的DataFormatString来格式化列,象DataFormatString="{0:d}"显示日期格式。
l 设置PageSize="15"每页显示15行数据,AllowPaging="True" 为允许分页 。
整个HTML页代码:
<form id="Form1" method="post" runat="server">
<asp:datagrid id="dgOrder" runat="server" Height="515px" Width="718px" AutoGenerateColumns="False" AllowSorting="True" CellPadding="4" BorderWidth="1px" BorderColor="#A0ABEB" PageSize="15" BorderStyle="Solid" BackColor="White" GridLines="Vertical" ForeColor="Black" AllowPaging="True" ShowFooter="True">
<SelectedItemStyle ForeColor="White" BackColor="Black"></SelectedItemStyle>
<AlternatingItemStyle BackColor="#EEEEEE"></AlternatingItemStyle>
<HeaderStyle HorizontalAlign="Center" ForeColor="White" BorderColor="#6876C5" BackColor="#6876C5"></HeaderStyle>
<FooterStyle ForeColor="White" BackColor="#6876C5"></FooterStyle>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<FONT face="">
<asp:CheckBox id="Cb" runat="server"></asp:CheckBox></FONT>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="orderid" SortExpression="orderid" HeaderText="ID">
<HeaderStyle Width="180px"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="ShipCountry" SortExpression="ShipCountry" HeaderText="ShipCountry">
<HeaderStyle Width="180px"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="ShippedDate" SortExpression="ShippedDate" HeaderText="ShippedDate" DataFormatString="{0:d}">
<HeaderStyle Width="180px"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="Freight" SortExpression="Freight" HeaderText="Freight">
<HeaderStyle Width="180px"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="ShipAddress" SortExpression="ShipAddress" HeaderText="ShipAddress">
<HeaderStyle Width="480px"></HeaderStyle>
</asp:BoundColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="Black" Position="TopAndBottom" BackColor="White" Mode="NumericPages"></PagerStyle>
</asp:datagrid>
</form>
#8
'得到数据视图,参数为要排序的列
Private Function GetDv(ByVal strSort As String) As DataView
'定义数据库连接
Dim dv As DataView
Dim CN As New SqlConnection()
Try
'初始化连接字符串
CN.ConnectionString = "data source=pmserver;
initial catalog=Northwind;persist security info=False;user id=sa;Password=sa;"
CN.Open()
'从NorthWind得到orders表的数据
Dim adp As SqlDataAdapter = New SqlDataAdapter("select * from orders", CN)
Dim ds As New DataSet()
adp.Fill(ds)
'得到数据视图
dv = ds.Tables(0).DefaultView
Catch ex As Exception
#If DEBUG Then
Session("Error") = ex.ToString()
Response.Redirect("../error.aspx") '跳转程序的公共错误处理页面
#End If
Finally
'关闭连接
CN.Close()
End Try
'排序
dv.Sort = strSort
Return dv
End Function
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
If Not IsPostBack Then
ViewState("strSort") = "orderid"
dgOrder.DataSource = GetDv(ViewState("strSort").ToString())
dgOrder.DataBind()
End If
End Sub
'排序
Private Sub dgOrder_SortCommand(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles dgOrder.SortCommand
dgOrder.CurrentPageIndex = 0
'得到排序的列
ViewState("strSort") = e.SortExpression.ToString()
dgOrder.DataSource = GetDv(ViewState("strSort").ToString())
dgOrder.DataBind()
End Sub
'分页
Private Sub dgOrder_PageIndexChanged(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dgOrder.PageIndexChanged
'得到分页的页号
dgOrder.CurrentPageIndex = e.NewPageIndex
dgOrder.DataSource = GetDv(ViewState("strSort").ToString())
dgOrder.DataBind()
End Sub
Private Function GetDv(ByVal strSort As String) As DataView
'定义数据库连接
Dim dv As DataView
Dim CN As New SqlConnection()
Try
'初始化连接字符串
CN.ConnectionString = "data source=pmserver;
initial catalog=Northwind;persist security info=False;user id=sa;Password=sa;"
CN.Open()
'从NorthWind得到orders表的数据
Dim adp As SqlDataAdapter = New SqlDataAdapter("select * from orders", CN)
Dim ds As New DataSet()
adp.Fill(ds)
'得到数据视图
dv = ds.Tables(0).DefaultView
Catch ex As Exception
#If DEBUG Then
Session("Error") = ex.ToString()
Response.Redirect("../error.aspx") '跳转程序的公共错误处理页面
#End If
Finally
'关闭连接
CN.Close()
End Try
'排序
dv.Sort = strSort
Return dv
End Function
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
If Not IsPostBack Then
ViewState("strSort") = "orderid"
dgOrder.DataSource = GetDv(ViewState("strSort").ToString())
dgOrder.DataBind()
End If
End Sub
'排序
Private Sub dgOrder_SortCommand(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles dgOrder.SortCommand
dgOrder.CurrentPageIndex = 0
'得到排序的列
ViewState("strSort") = e.SortExpression.ToString()
dgOrder.DataSource = GetDv(ViewState("strSort").ToString())
dgOrder.DataBind()
End Sub
'分页
Private Sub dgOrder_PageIndexChanged(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dgOrder.PageIndexChanged
'得到分页的页号
dgOrder.CurrentPageIndex = e.NewPageIndex
dgOrder.DataSource = GetDv(ViewState("strSort").ToString())
dgOrder.DataBind()
End Sub
#9
2.考虑用 xmlhttp
#10
1.翻页的问题:翻页时要保存控件的选择状态,用Datagrid怎么解决?用数组还是其他的?
这个问题 在孟子E章 上有很详细的解释
2.如果有人答了一部分想保存,如何保存?想再答时怎么提取?(有翻页的)
我想 你可以设置一个 练习 和 答题的选择
如果是在做练习 你可以把他的做的试题的ID 全部保存下来(这个ID 指的是 试题在数据库里的ID,当然还要保存他所做的所有试题的试题ID,练习试卷是从数据库里自动抽题出来组成的)然后保存在 一个表中或者保存在XML 中 当他登陆的时候如果是 处于练习状态 就去数据库里读取这个ID数据 然后用孟子E章 里的方法 给DATAGRID上的CHEKBOX或则RADIOBUTTON 赋值
#1
第一个问题的答案,这里看,跨页面多选择
http://dotnet.aspx.cc/ShowDetail.aspx?id=F43AF9A5-2C2E-4AA6-E976-21E9569F5A8A
http://dotnet.aspx.cc/ShowDetail.aspx?id=F43AF9A5-2C2E-4AA6-E976-21E9569F5A8A
#2
up
:)
:)
#3
页面少的话用panel做翻页偶感觉也不错
#4
up
#5
panel做翻页
#6
用panel做翻页
或去【孟宪会之精彩世界】
http://dotnet.aspx.cc/ShowDetail.aspx?id=F43AF9A5-2C2E-4AA6-E976-21E9569F5A8A
或去【孟宪会之精彩世界】
http://dotnet.aspx.cc/ShowDetail.aspx?id=F43AF9A5-2C2E-4AA6-E976-21E9569F5A8A
#7
为了方便起见,我们连接SQL Server 2000的NorthWind数据库的Orders表,从数据库里得到此表的数据视图。利用DataGrid的SortCommand事件实现排序。用一个模板列加上CheckBox控件实现选择。可用DataGrid的属性生成器的“分页”选项或者自己修改HTML实现分页。
HTML:
l 添加一个DataGrid,命名为dgOrder。
l 添加了一个模板列,模板列里放一个名为Cb的CheckBox控件。此列用来实现选择
l 为要排序的每个列加上排序表达式SortExpression。
l 利用列的DataFormatString来格式化列,象DataFormatString="{0:d}"显示日期格式。
l 设置PageSize="15"每页显示15行数据,AllowPaging="True" 为允许分页 。
整个HTML页代码:
<form id="Form1" method="post" runat="server">
<asp:datagrid id="dgOrder" runat="server" Height="515px" Width="718px" AutoGenerateColumns="False" AllowSorting="True" CellPadding="4" BorderWidth="1px" BorderColor="#A0ABEB" PageSize="15" BorderStyle="Solid" BackColor="White" GridLines="Vertical" ForeColor="Black" AllowPaging="True" ShowFooter="True">
<SelectedItemStyle ForeColor="White" BackColor="Black"></SelectedItemStyle>
<AlternatingItemStyle BackColor="#EEEEEE"></AlternatingItemStyle>
<HeaderStyle HorizontalAlign="Center" ForeColor="White" BorderColor="#6876C5" BackColor="#6876C5"></HeaderStyle>
<FooterStyle ForeColor="White" BackColor="#6876C5"></FooterStyle>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<FONT face="">
<asp:CheckBox id="Cb" runat="server"></asp:CheckBox></FONT>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="orderid" SortExpression="orderid" HeaderText="ID">
<HeaderStyle Width="180px"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="ShipCountry" SortExpression="ShipCountry" HeaderText="ShipCountry">
<HeaderStyle Width="180px"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="ShippedDate" SortExpression="ShippedDate" HeaderText="ShippedDate" DataFormatString="{0:d}">
<HeaderStyle Width="180px"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="Freight" SortExpression="Freight" HeaderText="Freight">
<HeaderStyle Width="180px"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="ShipAddress" SortExpression="ShipAddress" HeaderText="ShipAddress">
<HeaderStyle Width="480px"></HeaderStyle>
</asp:BoundColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="Black" Position="TopAndBottom" BackColor="White" Mode="NumericPages"></PagerStyle>
</asp:datagrid>
</form>
HTML:
l 添加一个DataGrid,命名为dgOrder。
l 添加了一个模板列,模板列里放一个名为Cb的CheckBox控件。此列用来实现选择
l 为要排序的每个列加上排序表达式SortExpression。
l 利用列的DataFormatString来格式化列,象DataFormatString="{0:d}"显示日期格式。
l 设置PageSize="15"每页显示15行数据,AllowPaging="True" 为允许分页 。
整个HTML页代码:
<form id="Form1" method="post" runat="server">
<asp:datagrid id="dgOrder" runat="server" Height="515px" Width="718px" AutoGenerateColumns="False" AllowSorting="True" CellPadding="4" BorderWidth="1px" BorderColor="#A0ABEB" PageSize="15" BorderStyle="Solid" BackColor="White" GridLines="Vertical" ForeColor="Black" AllowPaging="True" ShowFooter="True">
<SelectedItemStyle ForeColor="White" BackColor="Black"></SelectedItemStyle>
<AlternatingItemStyle BackColor="#EEEEEE"></AlternatingItemStyle>
<HeaderStyle HorizontalAlign="Center" ForeColor="White" BorderColor="#6876C5" BackColor="#6876C5"></HeaderStyle>
<FooterStyle ForeColor="White" BackColor="#6876C5"></FooterStyle>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<FONT face="">
<asp:CheckBox id="Cb" runat="server"></asp:CheckBox></FONT>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="orderid" SortExpression="orderid" HeaderText="ID">
<HeaderStyle Width="180px"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="ShipCountry" SortExpression="ShipCountry" HeaderText="ShipCountry">
<HeaderStyle Width="180px"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="ShippedDate" SortExpression="ShippedDate" HeaderText="ShippedDate" DataFormatString="{0:d}">
<HeaderStyle Width="180px"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="Freight" SortExpression="Freight" HeaderText="Freight">
<HeaderStyle Width="180px"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="ShipAddress" SortExpression="ShipAddress" HeaderText="ShipAddress">
<HeaderStyle Width="480px"></HeaderStyle>
</asp:BoundColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="Black" Position="TopAndBottom" BackColor="White" Mode="NumericPages"></PagerStyle>
</asp:datagrid>
</form>
#8
'得到数据视图,参数为要排序的列
Private Function GetDv(ByVal strSort As String) As DataView
'定义数据库连接
Dim dv As DataView
Dim CN As New SqlConnection()
Try
'初始化连接字符串
CN.ConnectionString = "data source=pmserver;
initial catalog=Northwind;persist security info=False;user id=sa;Password=sa;"
CN.Open()
'从NorthWind得到orders表的数据
Dim adp As SqlDataAdapter = New SqlDataAdapter("select * from orders", CN)
Dim ds As New DataSet()
adp.Fill(ds)
'得到数据视图
dv = ds.Tables(0).DefaultView
Catch ex As Exception
#If DEBUG Then
Session("Error") = ex.ToString()
Response.Redirect("../error.aspx") '跳转程序的公共错误处理页面
#End If
Finally
'关闭连接
CN.Close()
End Try
'排序
dv.Sort = strSort
Return dv
End Function
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
If Not IsPostBack Then
ViewState("strSort") = "orderid"
dgOrder.DataSource = GetDv(ViewState("strSort").ToString())
dgOrder.DataBind()
End If
End Sub
'排序
Private Sub dgOrder_SortCommand(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles dgOrder.SortCommand
dgOrder.CurrentPageIndex = 0
'得到排序的列
ViewState("strSort") = e.SortExpression.ToString()
dgOrder.DataSource = GetDv(ViewState("strSort").ToString())
dgOrder.DataBind()
End Sub
'分页
Private Sub dgOrder_PageIndexChanged(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dgOrder.PageIndexChanged
'得到分页的页号
dgOrder.CurrentPageIndex = e.NewPageIndex
dgOrder.DataSource = GetDv(ViewState("strSort").ToString())
dgOrder.DataBind()
End Sub
Private Function GetDv(ByVal strSort As String) As DataView
'定义数据库连接
Dim dv As DataView
Dim CN As New SqlConnection()
Try
'初始化连接字符串
CN.ConnectionString = "data source=pmserver;
initial catalog=Northwind;persist security info=False;user id=sa;Password=sa;"
CN.Open()
'从NorthWind得到orders表的数据
Dim adp As SqlDataAdapter = New SqlDataAdapter("select * from orders", CN)
Dim ds As New DataSet()
adp.Fill(ds)
'得到数据视图
dv = ds.Tables(0).DefaultView
Catch ex As Exception
#If DEBUG Then
Session("Error") = ex.ToString()
Response.Redirect("../error.aspx") '跳转程序的公共错误处理页面
#End If
Finally
'关闭连接
CN.Close()
End Try
'排序
dv.Sort = strSort
Return dv
End Function
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
If Not IsPostBack Then
ViewState("strSort") = "orderid"
dgOrder.DataSource = GetDv(ViewState("strSort").ToString())
dgOrder.DataBind()
End If
End Sub
'排序
Private Sub dgOrder_SortCommand(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles dgOrder.SortCommand
dgOrder.CurrentPageIndex = 0
'得到排序的列
ViewState("strSort") = e.SortExpression.ToString()
dgOrder.DataSource = GetDv(ViewState("strSort").ToString())
dgOrder.DataBind()
End Sub
'分页
Private Sub dgOrder_PageIndexChanged(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dgOrder.PageIndexChanged
'得到分页的页号
dgOrder.CurrentPageIndex = e.NewPageIndex
dgOrder.DataSource = GetDv(ViewState("strSort").ToString())
dgOrder.DataBind()
End Sub
#9
2.考虑用 xmlhttp
#10
1.翻页的问题:翻页时要保存控件的选择状态,用Datagrid怎么解决?用数组还是其他的?
这个问题 在孟子E章 上有很详细的解释
2.如果有人答了一部分想保存,如何保存?想再答时怎么提取?(有翻页的)
我想 你可以设置一个 练习 和 答题的选择
如果是在做练习 你可以把他的做的试题的ID 全部保存下来(这个ID 指的是 试题在数据库里的ID,当然还要保存他所做的所有试题的试题ID,练习试卷是从数据库里自动抽题出来组成的)然后保存在 一个表中或者保存在XML 中 当他登陆的时候如果是 处于练习状态 就去数据库里读取这个ID数据 然后用孟子E章 里的方法 给DATAGRID上的CHEKBOX或则RADIOBUTTON 赋值