views:

49

answers:

2

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>
            <% } %>
............................

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?

A: 

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.

TheGeekYouNeed
Let me explain more deeper:my datatable contains rows (i checked). Difference in columns. If some param "objectType == 1" then i receive one datatable else another with different kit of columns.In aspx-page this work perfect! The same code in ascx-control doesn't work.Yes, if my "objectType == 1" then my repeater receive datatable with absent SOTName column. But my condition <% if (GetObjectTypeName() == "Sot") { %>special for this! But this don't work in ASCX
Pavel
A: 

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.

devio
Pavel
Why in ASCX databinding raise early than if/else condition?
Pavel