asp.net gridview对象数据源自定义分页我在哪里出错? [英] asp.net gridview object datasource custom paging where am I going wrong?

查看:53
本文介绍了asp.net gridview对象数据源自定义分页我在哪里出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个绑定到对象数据源的网格视图.我创建了两种方法

Hi I have a grid view which is bound to a object datasource. I have created two methods

GetCPMDQueuesrchCount which gives the total number of records
and 
GetCPMDQueuesrchwhich accepts StartRowindex and PageSize as input parameters. 



我已按照此处给出的说明进行操作使用带有GridView的ObjectDataSource进行分页 [



I have followed the instructions given here Implement Paging using ObjectDataSource with GridView[^]

the code works fine if I set allow paging=false.
The moment I set allow paging=true in the gridview everything works fine(I get the data from my business methods but it is not getting bound to my gridview).:confused:
I get a blank screen.

The paging and sorting was working fine until yesterday evening and some code change and my code has stopped working. :doh:

without enabling paging to true my code works fine.Even sort happens based on the header click.But once I enable allow paging=true my grid is not getting bound to the data.

where am I going wrong.

Can anyone help me out in this

Gridview code in the aspx file

<pre lang="xml"><asp:GridView ID="gvDisplay"
runat="server" CssClass="tablestyle" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="false" CellPadding="4" DataSourceID="ObjectDataSource1"
>

<HeaderStyle CssClass="headerstyle" />
<PagerSettings Mode="NumericFirstLast"></PagerSettings>
<RowStyle CssClass="rowstyle" />
<PagerStyle HorizontalAlign="Right" />
<AlternatingRowStyle CssClass="alternatingrowstyle" />

<Columns>
<asp:TemplateField HeaderText="Application Date" SortExpression="UpdateDatetime">
<ItemTemplate>
<asp:Label ID="lblApplicationDate" runat="server" Text=''<%# Eval("UpdateDatetime") %>''></asp:Label>
</ItemTemplate>
 </asp:TemplateField>
</Columns>
</asp:GridView>




对象数据源代码




object datasource code

<pre lang="xml"><asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetCPMDQueuesrch"
TypeName="CRiMSBusinessMethods.CRiMSBusinessMethods" EnablePaging="True"
SelectCountMethod="GetCPMDQueuesrchCount" SortParameterName="sortExpression"
MaximumRowsParameterName="pagesize" StartRowIndexParameterName="startRowIndex"
onselecting="ObjectDataSource1_Selecting" onselected="ObjectDataSource1_Selected"
>

<SelectParameters>
<asp:Parameter Name="UserId" Type="String" />
<asp:Parameter Name="RoleID" Type="Int32" />
<asp:Parameter Name="Action" Type="Int32" />
<asp:Parameter Name="CptyType" Type="Int32" />
<asp:Parameter Name="BeginDate" Type="DateTime" />
<asp:Parameter Name="EndDate" Type="DateTime" />
<asp:Parameter Name="NoOfDays" Type="Int32" />
<asp:Parameter Name="regionid" Type="Int32" />
<asp:Parameter Name="startRowIndex" Type="Int32" />
<asp:Parameter Name="sortExpression" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>


推荐答案

我能够在上周五的午夜破解罪魁祸首.天哪,这个问题让我恶梦了,我很高兴自己解决了这个问题.解决方案很简单.
我的searchcount方法出现问题.
我的计数方法是重现数据正确的数据计数.但是似乎有些数据类型不匹配.如果我将计数硬编码为.
I was able to crack the culprit last friday at midnight. Gosh man this problem was giving me nightmares and I am glad I fixed it. The solution is simple.
There was a problem in my searchcount method.
My count method was returing data proper data count. But there is some data type mismatch it seems. If I hardcode the count as .
return 16 


它会工作,但是如果我将它绑定到一个int变量并返回该变量,它将无法工作.如果您将其硬编码为16,则它是一个结构系统.Int32数据类型,但是如果您返回一个int变量,则它只是一个Int32变量.我认为问题出在这里.


it would work but if I bind it to a int variable and return the variable it wouldnt work. If you hardcode as 16 it is a struct system.Int32 datatype but if you return a int variable it is just a Int32 variable. I think the problem lies here.

public int GetsrchCount(BeginDate,EndDate) 
{ 
    int intrec; 
    intrec = 23; 
    return intrec;  
 } 


然后幸运的是,经过长时间的搜索,我在某个地方找到了该解决方案.我将count方法的返回类型更改为static int


Then after a long search luckily I found this solution some where. I changed the return type of my count method to static int

public static int GetsrchCount(DateTime BeginDate, DateTime EndDate) 
    { 
        int intrec; 
        intrec = 23; 
        return intrec;  
     } 

数据类型不匹配.现在它像微风一样工作

There is some mismatch in the datatypes. It works like a breeze now




根据您的代码

Hi,

as per your code

<asp:GridView ID="gvDisplay"
runat="server" CssClass="tablestyle" AllowPaging=true AllowSorting="True"
AutoGenerateColumns="false" CellPadding="4" DataSourceID="ObjectDataSource1"
>



我表明网格的属性设置存在问题.您已经编写了[AllowPaging = true],但应为[AllowPaging ="True"],因此请根据此进行更改并尝试.



I show that there is a problem in property setting of the grid. you had written [AllowPaging=true] but it should be [AllowPaging="True"] like this so change it according to that and try it.


这篇关于asp.net gridview对象数据源自定义分页我在哪里出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆