开发者

In ASCX-control not doing IF/ELSE condition

There ASCX-controls that the program-loaded onto the page. In a Repeater control in which, depending on the conditions displayed a different set of COLUMNS and DataTable with a different set of columns.

So, on the ASPX-page, this construction work Good.

    <ItemTemplate>
        <tr class="objectrow" href="<%# GetCompleteViewObjectLink(Convert.ToInt32(Eval("ID_Object")))%>">
            <td align="center" class="c1">
                <%# Eval("ID_Object") %>
            </td>
            <% if (GetObjectTypeName() == "Sot")
               { %>
            <td align="center" class="c6">
                <%# Eval("SOTName") != DBNull.Value ? Eval("SOTName") : ""%>
            </td>
     开发者_C百科       <% } %>
............................

But in program-loaded to page ASCX-control I have an Exception:

Error: DataBinding: 'System.Data.DataRowView' does not contain a property named SOTName.

and another does not conform: in aspx-page my breakpoint on row

<% if (GetObjectTypeName() == "Sot")

was work off. But in ascx-control NOT.

Please, help! Why behaviour is so different? How to be?


Check your data for actual rows, i.e. row count? I would bet your DataSource is null.

I don't think you're getting data when you think you should be.

The Page Load event of the user control will execute before the aspx Page Load. If you are getting some type of parameter for your query in the .ascx in the Page Load of the .aspx, you ought to grab that in the Page_Init of the .aspx.


As TheGeekYouNeed points out, it's crucial to know when the DataSource of the Repeater is defined, as the control's events are processed before the page events.

You can add code like

<td>GetObjectTypeName='<%# GetObjectTypeName() %>'</td>

to find out whether the if() condition applies for your data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜