.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Post New Web Links

Cannot access Label inside Repeater - "Object reference not set..."

Posted By:      Posted Date: August 27, 2010    Points: 0   Category :ASP.Net
 

I have a button on a page with a Repeater and an ObjectDataSource. To give credit where credit is due, the Repeater's paging functionality is courtesy of ScottGu. (However, I'm using ASP.NET 4.0 and SQL Server 2008, as opposed to ASP.NET 2.0 and SQL Server 2005.)

Anyway, in the button's click event, I need to access the Text property of a Label that's inside the Repeater because it's used as an input parameter in a stored procedure. I'm getting a NullReferenceException when trying to access the Label's Text property. I have researched this error and have tried a few different solutions (involving FindControl and the Repeater's ItemDataBound event), but I haven't been able to get it to work. Any suggestions, in VB or C#, would be greatly appreciated. The code is below.

somepage.aspx

<asp:Repeater ID="rptText" runat="server" DataSourceID="tbsDataSource">
<HeaderTemplate>
<table width="100%" cellspacing="1">
</HeaderTemplate>
<ItemTemplate>
<%-- some rows removed for brevity --%>
<tr>
<td><asp:Label


View Complete Post


More Related Resource Links

Strange Repeater Error, Object reference not set, Label not visible etc etc..

  
Hi Everyone,This is very strange and as of yet I cant seem to get round it, although it is a somewhat easy error to identify it is however becoming very annoying as everything I try doesn't seem to work...The repeater displays results for upcoming subscribers birthdays and after their day and month ("dd/mm/") I have a label to display the current year. This causes the old error of: Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.Source Error:  Line 55: Label lblYear = e.Item.FindControl("lblYear") as Label;Line 56: Line 57: lblYear.Text = DateTime.Now.Year.ToString();Line 58: }Line 59: As you can see the object is set correctly - The ASPX is below, for saving time on reading etc I've posted the repeater script only and not the whole page, although I can do if needs be.I've tried a number of things with subtle differences but to no avail: with Literal, same error - Tried inserting the year directly via <%#((system.datetime).now.year.tostring())%> or something to that effect, this also doesnt

LinkButton inside Repeater

  

Hi.

I have Repeater, which consists of LinkButon and Literal. LinkButon and Literal are whole thing by implication. I want get value from Literal, when user click on corresponding LinkButton.

TIA 


unable to access control inside webuser control

  

hi

I have used calender web user control inside my project where i took textbox,button and calender.....but after dragging onto my aspx page....i am unable to access this textbox,calender and button on aspx page...Pls help me to find out the solution.


Repeater issue, all code inside Repeater are not shown

  

I have a Repeater who should show some data from my ms.sql server. But all code inside the Repater is not shown on my .aspx page. What am i doing wrong. I have a similar Repeater on another page and there it works fine.

 

 <div class="AnsaettelseKontrakt Folders">
      	            <table cellpadding="0" cellspacing="0" width="750px" align="right">
                        <tr>
                            <th class="BrugerHeader" style="width:300px;">Filnavn</th>
                            <th class="BrugerHeader" style="width:80px;">Størrelse</th>
                            <th class="BrugerHeader" style="width:150px;">Dato</th>
                            <th class="BrugerHeader" style="width:180px;" colspan="2">Brugere</th>
                            <th class="BrugerHeader" style="width:40px;">Værktøjer</th>
                        </tr>
                        <asp:Repeater ID="RepeaterAns" runat="server" onitemcommand="Repeater1_ItemCommand" >
                            <ItemTemplate>
                                <tr class="Br

XML Repeater Inside Conditional Statement

  

Hi all,

I'm working on an VB.Net application which have 2 nasted repeaters using xml as data source. I need to add a conditional statement withen the first repeater ItemTemplate as follows:

<ItemTemplate>
	<%# IIf(XPath("@type")= 3 , "<html>", "<div id=""tblPages"" runat=""server""><divsub""><h2>"   &  XPath("@title") &  "</h2><ul class="sublinks"><asp:repeater id=""rpPages"" DataSource=""XPathSelect("@page")"" runat=""server""><ItemTemplate><li></li></ItemTemplate></asp:Repeater></ul></div></div>" ) %>
</ItemTemplate>



The problem come when I  try to add the

DataSource='<%# XPathSelect("page") %>'



so I get an error.

Does anyone have idea if the above code may work?

thank you
Hany


label inside table inside div won't show

  
I have a label inside a table cell that is coded to change backcolor conditionally. The table is inside a div tag. The label doesn't appear at runtime. Has anyone experienced this before? Is there a workaround? Thanks. 

Get value of a label control inside the DetailsView

  
Hi everyone, I have a databound label control (i.e. Label 3) inside an Item Template that's in a DetailsView control. I just need to get the value of those label and compare it to some string. I tried several ways (i.e. Find control, DetailsView.Row) but nothing seems to work. I don't know if I'm using the FindControl methos correctly or if I need to access the Row first and do the findcontrol method.  Protected Sub DetailsView4_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles DetailsView4.DataBound 'If (DetailsView4.Rows(2).Cells(1).ToString = "Regular") Then 'Label3.ForeColor = Drawing.Color.Azure 'End If 'Dim StatusQualifierContainer As Label 'Dim S As String 'StatusQualifierContainer = DetailsView4.FindControl(Label3.Text) 'S = StatusQualifierContainer.Text 'If S = "Regular" Then 'Label5.ForeColor = Drawing.Color.Aqua 'End If 'Dim C As Label = DetailsView4.FindControl("Label3") 'If C.Text = "Regular" Then 'Label3.ForeColor = Drawing.Color.DarkBlue 'End If 'Dim headerRow As DetailsViewRow = DetailsView4.HeaderRow 'Dim lblText As Label = CType(headerRow.FindControl("Label3"), Label)

Access Model Validation inside Custom Model Binder.

  
Hello,Is it possible, inside a Custom Model Binder, to fire "something" that "says" the value is invalid so it gets handled by validation part?Basically, I am getting an exception when the value for the property is invalid.Thank You,Miguel

I need to be able to disable a button inside a repeater control when an item in the data is <1

  
For example, I have an inventory table. If any one of the items is less then one, I need to disable the button. <asp:Repeater id="repeater1" <ItemTemplate> <asp:Button id=btnSize /> </ItemTemplate> </asp:Repeater>  

how to access items inside Sharepoint List Folder

  
hi all i have a list with structure as below  QuckList(List)                A(Folder)                       1(List Items)                       2(List Items)                B(Folder)                        1(List Items)   i have to display the List items inside the folder in drop down   i am able to access the folder as Splistitem, but not able to access the items inside the folder   any ideas how to access the items inside the List Folder   ragava_28

Folder inside the List shows Access Denied when try to open using Manage Content Structure

  
Hi All, We are facing this issue in one of our site, when accessing the folder from Manage content structure. Folder is inside a list which uses a folder content type. When we try to open this folder use manage content and structure it throws access denied. any idea how we can check this as we the permissions are properly inherited and all the folders are checked in . Please update what else we can check.   Thanks, Jasjeet SIngh

How to get the values of controls placed inside the repeater

  
Hi friends.........         In my code i will get the controls dynamically according to the Family members count.Now i need to display the values of each control individually which are placed inside the repeater control.  plz plz go through my code then you can understand my situation.I want to get the values of txtMemberName,drpRelationship,txtDateofBirth as in my database(dataset) for each control.This is my code:.aspx page<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="familyDetails.aspx.cs" Inherits="UI.familyDetails" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server">    <title>Untitled Page</title></head><body>    <form id="form1" runat="server">    <div>    <asp:Button ID="btnGetFamilydetails" runat="server" Text="Family Details"             onclick="btnGetFamilydetails_Click" />          <asp:Repeater ID="repFamilyDetai

Conditional inside repeater

  
Hi,I'm mainly front-end so forgive me if this is a really stupid question, but I have a repeater control which is pulling data from a database into a web page.  In that data there is a field showing 'unread messages' (it's a simple numeric field in the database).  What I want to do is something like this:<%if (#DataBinder.Eval(Container,"DataItem.Unread")>0 {%> <p>NEW MESSAGES!</p> <%}%> However, I can't seem to get the conditional to work on a repeater like this.Can anyone suggest how to get this working?Many thanks...

linkbutton inside repeater

  
Hi All-How can I make a linkbutton inside a repeater open a new browser window on click?<asp:LinkButton ID="LinkButton4" runat="server" PostBackUrl='<%# string.Format("~/Products.aspx/{0}",Eval("URL")) %>'>Details </asp:LinkButton>                                           
Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend