Saturday, March 24, 2012

asp label inside an accordion content

with the code behind i can not access the asp label in my accordion i get an error that says

Exception Details:System.NullReferenceException: Object reference not set to an instance of an object

my accordion looks like this :

<cc1:Accordion ID="GuestAccordian" runat="server" SelectedIndex="0"
FadeTransitions="True" FramesPerSecond="40" TransitionDuration="250" AutoSize="Fill" Visible="true" >
<Panes>
<cc1:AccordionPane ID="TodayCheckins" runat="server">
<Header><a href="http://links.10026.com/?link=" onclick="return false;">Today Check-ins</a></Header>
<Content>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</Content>
</cc1:AccordionPane>
<cc1:AccordionPane ID="FutureCheckins" runat="server">
<Header><a href="http://links.10026.com/?link=" onclick="return false;">Future Check-ins</a></Header>
<Content>adfadsf</Content>
</cc1:AccordionPane>
</Panes>
</cc1:Accordion>

my code behind is this :

string TodayCheckin = "";
using (SqlConnection conn = new SqlConnection(connString))
using (SqlCommand cmd = new SqlCommand(sql_stmt, conn))
{
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();

while (reader.Read())
{
TodayCheckin += reader.GetString(1);
}
conn.Close();
}
Label1.Text = TodayCheckin;

if I move the label out of the accordion it works fine, any ideas would be greatly appreciated.


try,

Label lbl = (Label) TodayCheckins.FindControl("Label1");
if(lbl != null) { lbl.Text = TodayCheckin; }

No comments:

Post a Comment