Add div conditionally says The name container does not exist in the current context

1.4k Views Asked by At

I want to add HTML div conditionally in rotator control. I am using the following code but it says "The name container does not exist in the current context" at DataBinder.Eval(Container.DataItem, "COL_ID")

<telerik:RadRotator ID="rtrList" runat="server" Width="830px" Height="100px"
                FrameDuration="10" RotatorType="ButtonsOver" ScrollDuration="450" WrapFrames="true"
                ItemWidth="100" ItemHeight="80" >
                <ItemTemplate>
                    <asp:HiddenField ID="hdfId" runat="server" Value='<%# Eval("COL_ID") %>' />

                    <div id="div" runat="server" title='<%# Eval("NAME") %>' class="widget_item">

                        <span>
                            <%# Eval("TITLE") %>
                        </span>
                    </div>

                <%if (Convert.ToInt32(DataBinder.Eval(Container.DataItem, "COL_ID")) % 2 == 0)

                   {%>

                    <div></div>

                <%} %>    

                </ItemTemplate>


            </telerik:RadRotator>

Please guide me where I am wrong. as I am using DataBinder.Eval & Container.DataItem for the first time.

Regards, Kash

2

There are 2 best solutions below

4
On

The error implies that this data item does not exist in the item bound to the control.

For example. If you were binding to a table, the table must have a column called "Col_ID" or this will throw an error.

Can you add your code for binding the control to the data source?

0
On

Use this syntax instead of the if:

<%# (Convert.ToInt32(DataBinder.Eval(Container.DataItem, "COL_ID")) % 2 == 0) ? "<div></div>" : "" %>