Wednesday, March 21, 2012

AJAX Accordian and asp:DataList incompatability

I am new to AJAX. and am trying to nest an asp:DataList into an accordian tag. When I try to run the show I get an "Object reference not set to an instance of an object" which tells me that the code in my VB file can't see the DataList.

Can anyone shed some light on this matter please.

Thanks

Can you post this part of code where exception is thrown?

-yuriy


yuriy

Thanks you for the help offer Here is the code. You may be wondering about the <cc1:AccordionPane (I think it's new in the ajaxtoolkit) which used to be <ajaxtoolkit:AccordionPane - I was also wondering about that, but it works under conditions where the HTML between the tags does not need to be populated from code.

1 <cc1:AccordionPane ID="AccordionPane2" runat="server">2 <Header>3 <a href="http://links.10026.com/?link=" onclick="return false;" class="accordionLink">Contact Detail</a>4 </Header>5 <Content>6 <asp:DataList ID="ProDetail" runat="server">7 <ItemTemplate>8 <table border="0" width="430" cellspacing="0" cellpadding="4">9 <tr>10 <td colspan="3" width="270" bgcolor="WhiteSmoke" align="left">11 <font color="blue" face="Verdana" size="2">Contact Person  <font color="red"12 face="Verdana" size="2">13<%# DataBinder.Eval(Container.DataItem, "ContactPerson")%>14 </font>15 </td>16 <td width="150" bgcolor="WhiteSmoke">17 </td>18 </tr>19 <tr>20 <td align="left">21 <font size="2" color="#333399">Tel</font>22 </td>23 <td>24 <font face="Arial" size="2">25<%# DataBinder.Eval(Container.DataItem, "Tel")%>26 </font>27 </td>28 <td align="left">29 <font size="2" color="#333399">Cell</font>30 </td>31 <td>32 <font face="Arial" size="2">33<%# DataBinder.Eval(Container.DataItem, "Cell")%>34 </font>35 </td>36 </tr>37 <tr>38 <td align="left">39 <font size="2" color="#333399">Street 1</font>40 </td>41 <td>42 <font face="Arial" size="2">43<%#DataBinder.Eval(Container.DataItem, "Street1")%>44 </font>45 </td>46 <td align="left">47 <font size="2" color="#333399">Street 2</font>48 </td>49 <td>50 <font face="Arial" size="2">51<%#DataBinder.Eval(Container.DataItem, "Street2")%>52 </font>53 </td>54 </tr>55 <tr>56 <td align="left">57 <font size="2" color="#333399">City</font>58 </td>59 <td>60 <font face="Arial" size="2">61<%# DataBinder.Eval(Container.DataItem, "City")%>62 </font>63 </td>64 <td align="left">65 <font size="2" color="#333399">Web Site</font>66 </td>67 <td>68 <font face="Arial" size="2">69<%# DataBinder.Eval(Container.DataItem, "Website")%>70 </font>71 </td>72 </tr>73 </table>74 </ItemTemplate>75 </asp:DataList>76 </Content>77 </cc1:AccordionPane>

Hi,

From the code I assume that you manually assign DataSource property and call DataBind() method. It happens that at this time AccordionPane has not instantiated its templates yet. You need to force it create your controls in templates. The easiest way to do it so to search for some control in the pane.

Try adding

AccordionPane2.FindControl("nothing");

immediately before you access your DataList control to make data binding.

(you can try adding this AccordionPane2.FindControl("nothing"); as the first line of you Page_Load as well).

-yuriy
http://couldbedone.blogspot.com


yuriy

Thank you ever so much for your help, it worked!

No comments:

Post a Comment