Click here to Skip to main content
15,909,242 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to access item template element of datalist in code behind file but i get Object reference not set to an instance of an object exception in following code
C#
protected void Page_Load(object sender, EventArgs e)
    {


Label lb = (Label)DataList1.FindControl("Label3");
Line 18: Response.Write(lb.Text);
}
hOW I CAN solve this error i have also tried Datalist_ItemBound Event but it also gives the same error
and if possible please share a tutorial related to accessing datalist items in code behind file plzzzzz
thanks
Posted
Comments
Ramug10 20-Feb-14 2:41am    
Show me your source code of datalist.
irfanniazi 20-Feb-14 2:45am    
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1">
<itemtemplate>

<asp:Label ID="QuestiontextLabel" runat="server"
Text='<%# Eval("Questiontext") %>' />
<br />

<asp:Label ID="Label1" runat="server"
Text='<%# Eval("QuestionID") %>' Visible="false" />
<br />
<asp:Label ID="Label3" runat="server"
Text='<%# Eval("Answertype") %>' />
<br />
<asp:RadioButtonList ID="RadioButtonList1" runat="server"
DataSourceID="SqlDataSource1" DataTextField="Choicetext"
DataValueField="Choicetext">

this is my datalist
ashok rathod 3-Apr-14 5:14am    
You can check below link..

http://www.codeproject.com/Questions/659892/how-to-use-selected-item-template-in-datalist

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900