views:

208

answers:

3

I'm trying to add custom paging to my site using the ObjectDataSource paging. I believe I've correctly added the stored procedures I need, and brought them up through the DAL and BLL. The problem I have is that when I try to use it on a page, I get an empty datagrid.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PageTest.aspx.cs" Inherits="developer_PageTest" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">
    <title></title>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ObjectDataSource ID="ObjectDataSource1" SelectMethod="GetMessagesPaged" EnablePaging="true"
            SelectCountMethod="GetMessagesCount" TypeName="MessageTable" runat="server" >
            <SelectParameters>
                <asp:Parameter Name="DeviceID" Type="Int32" DefaultValue="112" />
                <asp:Parameter Name="StartDate" Type="DateTime" DefaultValue="" ConvertEmptyStringToNull="true"/>
                <asp:Parameter Name="EndDate" Type="DateTime" DefaultValue="" ConvertEmptyStringToNull="true"/>
                <asp:Parameter Name="BasicMatch" Type="Boolean" ConvertEmptyStringToNull="true" DefaultValue="" />
                <asp:Parameter Name="ContainsPosition" Type="Boolean" ConvertEmptyStringToNull="true" DefaultValue="" />
                <asp:Parameter Name="Decoded" Type="Boolean" ConvertEmptyStringToNull="true" DefaultValue="" />
<%--                <asp:Parameter Name="StartRowIndex" Type="Int32" DefaultValue="10" />
                <asp:Parameter Name="MaximumRows" Type="Int32" DefaultValue="10" />
--%>            </SelectParameters>    
        </asp:ObjectDataSource>        

        <asp:GridView ID="GridView1" runat="server" DataSourceID="ObjectDataSource1" AllowPaging="true" PageSize="10"></asp:GridView>
        <br />

        <asp:Label runat="server" ID="lblCount"></asp:Label>

    </div>
    </form>
</body>
</html>

When I set EnablePaging to false on the ODS, and add the commented out StartRowIndex and MaximumRows params in the markup, I get data so it really seems like the data layer is behaving as it should. There's code in code file to put the value of the GetMessagesCount call in the lblCount, and that always has a sensible value in it.

I've tried breaking in the BLL and stepping through, and the backend is getting called, and it is returning what looks like the right information and data, but somehow between the ODS and the GridView it's vanishing.

I created a mock data source which returned numbered rows of random numbers and attached it to this form, and the custom paging worked so I think my understanding of the technique is good. I just can't see why it fails here!

Any help really appreciated.

(EDIT .. here's the code behind).

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;

public partial class developer_PageTest : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        lblCount.Text = String.Format("Count = {0}", MessageTable.GetMessagesCount(112, null, null, null, null, null))       
    }
}
A: 

Wild stab in the dark: What Happens if you set the StartRowIndex DefaultValue to 1?

<asp:Parameter Name="StartRowIndex" Type="Int32" DefaultValue="1" />
<asp:Parameter Name="MaximumRows" Type="Int32" DefaultValue="10" />
Luhmann
Hi Luhmann. Those parameters are only for debugging. When paging is enabled, the ObjectDataSource automatically supplies those to the BLL. If I disable paging and just want to test the standard databinding, I have to put those in so that the right method is called. If I put StartRowIndex to 1, I get the first 10 rows, as expected! But only when EnabledPaging="false".
JohnCC
A: 

hi johncc did you find out what was causing the problem. I am also stuck with the same problem can u help me out

Mr.X
Sorry Mr.X, I never solved the problem. I used a jquery ajax grid instead! If you do solve it, I'd love to know the answer.
JohnCC
I found that the problem was in the method which was returning the record count. In the return if i hard code the value to 16 like Return 16 i was getting the grid but if i set the value to a int variable and return it it does not work. still struggling with the task. will let you know once i solve it
Mr.X
A: 

hi Johncc I had the same problem and was finally 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.

My count method was returing data. But there is some data type mismatch it seems. If I hardcode the count as .

return 16

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; 
 }

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

Mr.X