This is a migrated thread and some comments may be shown as answers.

RadGrid Trying to Bind to Column With Visible=False

5 Answers 770 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Nathan
Top achievements
Rank 1
Nathan asked on 26 Oct 2011, 06:26 PM
I am suddenly getting the following error message:
DataBinding: 'System.Data.DataRowView' does not contain a property with the name '16'.

The grid is used for a timesheet application, and has 16 date columns.  The 16th column is added for months with 31 days.  For the first 15 days of the month, only columns 1-15 are shown, and column 16 is hidden.  The logic for hiding the column is simple; if the data contains the key word "hide" in the columns display field, it sets the columns visible property to false.  This should prevent the binding of the column from happening.  In fact, it has been working in production since January 1st, 2009.  However, after adding a column to the grid, this logic no longer works.  I reference all columns by unique name, not column number, so the addition of a column should not have changed the existing functionality.

Here is the column's definition:
<telerik:GridTemplateColumn DataField="16" HeaderStyle-Font-Size="8pt" FooterStyle-Font-Bold="true" 
    HeaderStyle-HorizontalAlign="Center" HeaderText="16" ItemStyle-HorizontalAlign="Center" SortExpression="16" UniqueName="16" 
    Visible="true">
    <ItemTemplate>
        <%# Eval("16")%>
    </ItemTemplate>
    <EditItemTemplate>
        <telerik:RadNumericTextBox ID="txt16" runat="server" MaxValue="24" MinValue="0" 
            NumberFormat-DecimalDigits="1" TabIndex="90" Text='<%# Bind("16") %>' 
            Width="20px" />
    </EditItemTemplate>
    <FooterStyle Font-Bold="True" HorizontalAlign="Center" VerticalAlign="Middle" 
        Width="26px" />
    <HeaderStyle Font-Size="8pt" HorizontalAlign="Center" VerticalAlign="Middle" 
        Width="26px" />
    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="26px" />
</telerik:GridTemplateColumn>

Here is the code that hides the column:
//Hide date columns that are needed for this reporting period (14 day and 15 day reporting periods)
if (dateheaderdisplaytext == "hide")
{
    //hide the columns that are not in this reporting date range.
    RadGrid1.MasterTableView.GetColumn(sequence).Visible = false;
}
else
{
    header[sequence].Text = dateheaderdisplaytext;
}

I have verified that the columns dateheaderdisplaytext is set to hide for column 16 (see attachment), and have also verified through Team Foundation Server that no code related to column 16 or the logic to hide the column has changed.  Additionally, I have verified that the Telerik control version is the same in production (where it is working) as on my development machine (where it is not working).  The version is 2010.3.1317.40. 

Please advise me as to what could have gone wrong.

Thanks,
Nathan

5 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 31 Oct 2011, 04:15 PM
Hi Nathan,

Thank you for contacting us.

DataBinding expressions are evaluated compile time, so it does not matter whether the binding will be needed runtime or not, this is the reason for the error message. This error message is shown, when there is no such field in the database/datatable/datarowview. Or when it is not included in the select statement for the respective control.

Please verify that:

  • Field labeled "16" is presented in the database.
  • This field is included in the select statement and any other SQL statement that might needed it(UPDATE, DELETE, INSERT).

I hope the provided information helps. If the issue persists, please send us a sample project or more information about your data source, and RadGrid's binding.

Kind regards,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Nathan
Top achievements
Rank 1
answered on 31 Oct 2011, 08:10 PM
As the original post described (with a picture of the exact data returned), the dataset does indeed exclude the column named 16.  It is NOT supposed to be there.  The purpose of the code is to hide the column (16) from the RadGrid so that it DOES NOT bind.  Again, this code has been working in production, in the exact maner described, for almost two full years.
0
Andrey
Telerik team
answered on 01 Nov 2011, 04:46 PM
Hello Nathan,

I reviewed the attached image again and the only thing that I noticed is that you do not have a column/datafield with unique name "16". However I saw that you have specific rows which have values "16" for daterangekey and sequence columns.

Datafield property of RadGrid's column takes as a value string representation of datasource filed, not a value from this field. This property should be set to an existing datafield. You should specify datasource field and when RadGrid creates the columns, this column would have cell which has value "16".

Rows in RadGrid represents the data and the columns represent the structure of the datasource. Each row consists of cells - one cell per column. These cells store the data.

Binding is applied to a column no matter the visible state of this column. Binding is executed earlier in the life cycle. That is why the error message is generated before column hiding.

All the best,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Nathan
Top achievements
Rank 1
answered on 01 Nov 2011, 05:11 PM
The value 16 that you see in the sequence data field also has a sister value in the datedisplay column that contains a text value of "hide".  This value is used in the code-behind to set the visible property of the column with the unique ID 16 to have a visible property value of false.  The column is not trying to bind to the data value for 16, rather using it to determine whether or not to render the column at runtime.  This should prevent the column from rendering, thereby preventing it from binding.  Again, this was working for darn near two years in this exact manner.  It was only within the past two weeks that this behavior changed.

Here is the code that should prevent the rendering (and therefore the client-side binding) of column 16:
//Hide date columns that are not needed for this reporting period (14 day and 15 day reporting periods)
if (dateheaderdisplaytext == "hide")
{
    RadGrid1.MasterTableView.GetColumn(sequence).Visible = false;
}
0
Iana Tsolova
Telerik team
answered on 02 Nov 2011, 03:44 PM
Hello Nathan,

Is it possible that someone renamed the field in the DataTable definition in the past few weeks? I checked your image and I cannot see a column with name 16. 16 is present only as a value for the daterangekey and sequence columns for the first record in the second data view.
You can try binding an ASP:GridView or another bound control to see if it works differently from RadGrid.

Regards,
Iana Tsolova
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
General Discussions
Asked by
Nathan
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Nathan
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or