asp.net mobile + object reference null exception

  • 13 years ago

    Hi, I am defining DeviceSpecific region in a ObjectList and trying to have header for each paginated page, header contains two labels whose text will set be after the results from the database like total number of records. When I try to execute the following code I am getting Object reference nullexception. I couldnt understand, could anyone please tell me, why I am getting that. Here is my code for aspx and code behind file.


    <mobile:Form Runat=server ID="form" Paginate=True>
    <mobile:ObjectList ID="rptPublications" Runat="server" OnPreRender="rptChecking_PreRender">
    <DeviceSpecific ID="dspChkAcct" Runat="server">
    <Choice>
    <HeaderTemplate>
    <mobile:Label ID="hitResults" Runat=server Font-Bold=True Font-Size=Normal StyleReference=title Text=""></mobile:Label>
    <mobile:Label ID="pageIndex" Runat=server Font-Size=Small Text=""></mobile:Label>
    </HeaderTemplate>
    <ItemTemplate>
    <mobile:Link ID="aViewTopic" Runat="server" Font-Size=Small NavigateUrl="" BreakAfter=True/>
    <mobile:Label ID="tpcDetails1" Runat=server Font-Size=Small BreakAfter=True></mobile:Label>
    <mobile:Label ID="tpcDetails2" Runat=server Font-Size=Small BreakAfter=True></mobile:Label>
    </ItemTemplate>
    <SeparatorTemplate><br /></SeparatorTemplate>
    </Choice>
    </DeviceSpecific>
    </mobile:ObjectList> </mobile:Form>


    Code Behind file

     protected void rptChecking_PreRender(object sender, EventArgs e) { pageCount = form.PageCount.ToString(); ((System.Web.UI.MobileControls.Label)rptPublications.Controls[0].FindControl("hitResults")).Text = "Search results for - " + searchKey + " (" + rptPublications.Items.Count + ")"; ((System.Web.UI.MobileControls.Label)rptPublications.Controls[1].FindControl("pageIndex")).Text = "Showing Page" + currentPage + " of " + pageCount + ", Total Records: " + results.ChildNodes.Count; foreach (ObjectListItem item in rptPublications.Items) { XmlNode node = (XmlNode)item.DataItem; if (node != null) { Label pubTitle = (Label)item.FindControl("pubTitle"); Link aViewTopic = (Link)item.FindControl("aViewTopic"); Label tpcDeatils1 = (Label)item.FindControl("tpcDetails1"); Label tpcDeatils2 = (Label)item.FindControl("tpcDetails2"); string pubId = node.Attributes["PubId"].Value; string title = node.Attributes["Title"].Value; string topicHeading = node.SelectNodes("//TopicHeading").Item(item.Index).InnerText; string topicID = node.SelectNodes("//TopicID").Item(item.Index).InnerText; string sequence = node.SelectNodes("//Sequence").Item(item.Index).InnerText; string topicType = node.SelectNodes("//TopicType").Item(item.Index).InnerText; bool isJournalAbout = Convert.ToBoolean(node.SelectNodes("//IsJournalAbout").Item(item.Index).InnerText); bool isJournalWelcome = Convert.ToBoolean(node.SelectNodes("//IsJournalWelcome").Item(item.Index).InnerText); string journalID = node.SelectNodes("//JournalId").Item(item.Index).InnerText; string author = node.SelectNodes("//Author").Item(item.Index).InnerText; string views = node.SelectNodes("//NoOfViews").Item(item.Index).InnerText; string comment = node.SelectNodes("//NoOfComments").Item(item.Index).InnerText; string mDate = node.SelectNodes("//ModifiedDate").Item(item.Index).InnerText; string topicLink = "/HNMobileApp/topic.aspx?tid=" + topicID; aViewTopic.Text = topicHeading; aViewTopic.NavigateUrl = topicLink; tpcDeatils1.Text = "Comments: " + comment + " | " + "Views: " + views; tpcDeatils2.Text = "By: " + author + " on " + mDate; } } } Thanks Aruna.G

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“C++: an octopus made by nailing extra legs onto a dog.” - Steve Taylor