我只想将GridView的PageSize设置为20或将AllowPaging设置为True。但是,在客户端或服务器端更改GridView的属性不会执行任何操作 - 它会停留在10行的默认分页中。
我仍然可以在Response.Redirect()
中运行Page_Load()
,因此我认为该页面没有错误。
我认为唯一可能导致复杂化的是JavaScript:我使用jQuery来操作GridView表,以便我可以使用DataTable.js对表进行排序。
我从未使用过VB.NET,所以任何指针都会受到赞赏。也许这是一个快速修复,但我对VB.NET一无所知,无法知道这个问题。
这是aspx页面:
<%@ Page Title="Available Vehicles" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="VehicleList.aspx.vb" Inherits="RentVehicle.VehicleList" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<script>
function ShowFull(ctrl) {
if (ctrl.style.height == '50px') { ctrl.style.height = '150px'; ctrl.style.width = '270px'; }
else {ctrl.style.height = '50px'; ctrl.style.width = '90px';
}}
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-32627957-1']);
_gaq.push(['_trackPageview']);
(function () {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<script type="text/javascript">
$(document).ready(function () {
// Fix up GridView to support THEAD tags
$("#<%=GridView1.ClientID%> tbody").before("<thead><tr></tr></thead>");
$("#<%=GridView1.ClientID%> thead tr").append($("#<%=GridView1.ClientID%> th"));
$("#<%=GridView1.ClientID%> tbody tr:first").remove();
});
</script>
<script type = "text/javascript">
// now flip ADA
$(document).ready(function() {
$('#<%=GridView1.ClientID%>').DataTable({
"aaSorting": [[2,'asc'], [3,'desc']]
});
});
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
<h2 style="text-align:center;">Available Vehicles</h2>
<div style="text-align:center;">
<p>Click on a thumbnail for a larger photograph of the vehicle.</p>
</div>
<div style="width: 100%; height: 2px; background: #F87431; overflow: hidden; padding-left:0px"></div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="0" CellSpacing="2" OnRowDataBound="OnRowDataBound" >
<Columns>
<asp:templatefield>
<itemtemplate>
<asp:image id="Image1" runat="server" onclick="ShowFull(this)" imageurl='<%#Eval("photo_large")%>' width="90px" Height="50px" />
</itemtemplate>
</asp:templatefield>
<asp:BoundField DataField="category_name" HeaderText="Type" SortExpression="category_name" />
<asp:TemplateField HeaderText="ADA" SortExpression="vehicle_name">
<ItemTemplate>
<asp:image id="Image2" runat="server" imageurl="images/disability-symbol.png" width="25px" Height="25px" style="margin-left:5px;" visible='<%# If((Eval("category_name").ToString().Equals("ADA Mini Van") OR Eval("category_name").ToString().Equals("ADA ProMaster")), "True", "False")%>' />
</ItemTemplate>
<ItemStyle Width="50px" />
</asp:TemplateField>
<asp:BoundField DataField="vehicle_name" HeaderText="Model" SortExpression="vehicle_name" />
<asp:BoundField DataField="internal_daily_rate" HeaderText="Internal Per Day" SortExpression="internal_daily_rate" DataFormatString="{0:C}" HeaderStyle-HorizontalAlign="Left" ><HeaderStyle HorizontalAlign="Left"></HeaderStyle>
<ItemStyle Width="70px" />
</asp:BoundField>
<asp:BoundField DataField="internal_mileage_rate" HeaderText="Internal Per Mile" SortExpression="internal_mileage_rate" DataFormatString="{0:C}"> <ItemStyle Width="70px" />
</asp:BoundField>
<asp:BoundField DataField="external_daily_rate" HeaderText="External Per Day" SortExpression="external_daily_rate" DataFormatString="{0:C}"><ItemStyle Width="70px" />
</asp:BoundField>
<asp:BoundField DataField="external_mileage_rate" HeaderText="External Per Mile" SortExpression="external_mileage_rate" DataFormatString="{0:C}"><ItemStyle Width="70px" />
</asp:BoundField>
<asp:TemplateField HeaderText="HOV*" > <ItemTemplate>
<asp:CheckBox ID="checkHOV" runat="server" HeaderText="HOV*" Checked='<%# If(Eval("high_occupancy").ToString() = "Y", "True", "False")%>' visible='<%# If(Eval("high_occupancy").ToString() = "Y", "True", "False")%>'></asp:CheckBox> </ItemTemplate>
<ItemStyle Width="44px" />
</asp:TemplateField>
<asp:CommandField HeaderText="Rent Me!" ButtonType="Image" InsertVisible="False" SelectImageUrl="~/Images/carovico.gif" ShowCancelButton="False" ShowHeader="True" ShowSelectButton="True" Visible="false"/>
<asp:TemplateField HeaderText="Rental Quantity">
<ItemTemplate>
<asp:Label ID="lblMaxNumber" runat="server" Text='<%# Eval("Max_number")%>' Visible = "false" />
<asp:DropDownList ID="DropDownList1" runat="server"> </asp:DropDownList>
</ItemTemplate>
<ItemStyle Width="70px" />
</asp:TemplateField>
</Columns>
</asp:GridView>
<div style="width: 100%; height: 2px; background: #F87431; overflow: hidden; padding-left:0px"></div> <br />
<div style="float:right;padding-right:85px"> <asp:Button ID="ButtonCheckout" runat="server" Text="Check Out" /><br />
<asp:Label ID="LabelErrorMsg" runat="server" Text="You have not chosen any vehicles." ForeColor="#FF3300" Visible="False"></asp:Label>
</div>
<p><strong>* High occupancy training required.</strong></p>
<p><strong>Note: Similar vehicle may be substituted within requested vehicle category depending on availability. </strong></p><br />
Garage/Motol Pool Map: <br /><asp:Image ID="Image2" runat="server" Height="172px" ImageUrl="~/Images/motorpool.gif" Width="275px" />
</asp:Content>
这是aspx.vb:
Public Class VehicleList
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
If IsNothing(Session("NetID")) Then
Response.Redirect("login.aspx")
ElseIf IsNothing(Session("LoggedUser")) Then
' users with net id logged in to see the info anyway ' Response.Redirect("aboutme.aspx")
End If
Dim Available_Vehicle As System.Data.DataSet = Rentalwrapper.RentalRequest.Get_Vehicle_list()
GridView1.DataSource = Available_Vehicle
GridView1.AllowPaging = False 'DOESNT WORK, HALP
GridView1.DataBind()
End If
LabelErrorMsg.Visible = False
End Sub
Protected Sub OnRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If (e.Row.RowType = DataControlRowType.DataRow) Then
'Find the DropDownList in the Row
Dim ddlCountries As DropDownList = CType(e.Row.FindControl("dropdownlist1"), DropDownList)
Dim LabelMaxNum As Label = CType(e.Row.FindControl("lblmaxnumber"), Label)
Dim max_number As Int32 = CInt(LabelMaxNum.Text)
For i As Int16 = 0 To max_number
ddlCountries.Items.Add(i.ToString)
Next
ddlCountries.SelectedValue = 0
End If
End Sub
Protected Sub ButtonCheckout_Click(sender As Object, e As EventArgs) Handles ButtonCheckout.Click
Dim SelectedVehicle As New ArrayList()
Dim vehicleNo As DropDownList, Quantity As Int16 = 0
For Each row In GridView1.Rows
vehicleNo = row.FindControl("dropdownlist1")
Quantity = CInt(vehicleNo.SelectedValue)
If Quantity > 0 Then
SelectedVehicle.Add(Quantity.ToString & " x " & row.cells(2).text) 'CType(row.findcontrol("vehicle_name"), TextBox).Text)
End If
Next
If SelectedVehicle.Count = 0 Then
LabelErrorMsg.Visible = True
Else
Session("SelectedVehicle") = SelectedVehicle
If IsNothing(Session("LoggedUser")) Then
Response.Redirect("aboutme.aspx")
Else
Response.Redirect("RentalDetail.aspx")
End If
End If
End Sub
End Class
此代码仍将GridView设置为默认的10行。我只是不想要它的页面!
答案 0 :(得分:1)
我明白了。我的登录页面中的数据库连接出现了问题,因此应用程序出错了。 AllowPaging = False
现在有效。这很奇怪,因为我可以做其他所有事情,但修改GridView ......哦。但这不是唯一的问题。
当您在客户端向GridView添加<tr>
时,GridView会变得非常愚蠢并开始分页应用程序,即使AllowPaging = False
也是如此。
在服务器端和客户端。
到目前为止,我对VB.NET的体验一直不好 - 希望我从这里开始顺利学习这条学习曲线。