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

Grouping error, datacolumn nor a datarelation groupedtable0

4 Answers 161 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Christian
Top achievements
Rank 1
Christian asked on 20 Mar 2011, 02:23 PM

.Net 3.5
Telerik 2010.3.1317.35

I have a datagrid that has defined columns, and autogenerated columns are set to false,
The dataseource is a datatable and all my databindings are set on datatextfields.

on itemdatabound i compare two of the fields ((int)maxRead and (int)maxNote) and depending on the result i set the row font to bold (to show unread posts)

but as soon as i group any of the columns i get,
"maxRead is neither a DataColumn nor a DataRelation for table GroupedTable0."

I tried adding the maxRead as a defined column in the grid but that gave the same result.

heres my code,
i get the error on the "if ((int)drw["maxRead"] != (int)drw["maxNote"

])'" row below.

 

 

 

 

 

 

protected void grCaseList_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item.DataItem is DataRowView)
        {
            DataRowView drw = (DataRowView)e.Item.DataItem;
            if ((int)drw["maxRead"] != (int)drw["maxNote"])
            {
                e.Item.Font.Bold = true;
            }
        }
    }


<telerik:RadGrid ID="grCaseList" runat="server" Skin="Windows7" 
    AllowPaging="True" AllowSorting="True" GridLines="None" ShowGroupPanel="True" 
        Width="100%" AutoGenerateColumns="False" 
        onitemdatabound="grCaseList_ItemDataBound">
<HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Windows7"></HeaderContextMenu>
  
    <MasterTableView EnableColumnsViewState="false">
        <CommandItemSettings ExportToPdfText="Export to Pdf">
        </CommandItemSettings>
        <RowIndicatorColumn>
            <HeaderStyle Width="20px"></HeaderStyle>
        </RowIndicatorColumn>
        <ExpandCollapseColumn>
            <HeaderStyle Width="20px"></HeaderStyle>
        </ExpandCollapseColumn>
        <Columns>
            <telerik:GridHyperLinkColumn DataTextField="cs_id" DataType="System.Int32" 
                FilterControlAltText="Filter cs_id column" HeaderText="ID" 
                UniqueName="cs_id" DataNavigateUrlFields="caseUrl">
            </telerik:GridHyperLinkColumn>
            <telerik:GridHyperLinkColumn DataTextField="cs_header" 
                FilterControlAltText="Filter cs_header column" HeaderText="Rubrik" 
                UniqueName="cs_header" DataNavigateUrlFields="caseUrl">
            </telerik:GridHyperLinkColumn>
            <telerik:GridHyperLinkColumn DataTextField="nt_us_name" 
                FilterControlAltText="Filter nt_us_name column" HeaderText="Senast ändrad av" 
                UniqueName="nt_us_name">
            </telerik:GridHyperLinkColumn>
            <telerik:GridDateTimeColumn DataField="cs_timePosted" 
                FilterControlAltText="Filter cs_timePosted column" HeaderText="Inlagt" 
                UniqueName="cs_timePosted" DataFormatString="{0:yy-MM-dd hh:mm}">
            </telerik:GridDateTimeColumn>
            <telerik:GridDateTimeColumn DataField="cs_timePlanned" 
                DataType="System.DateTime" FilterControlAltText="Filter cs_timePlanned column" 
                HeaderText="Planerat" UniqueName="cs_timePlanned" DataFormatString="{0:yy-MM-dd hh:mm}">
            </telerik:GridDateTimeColumn>
            <telerik:GridDateTimeColumn DataField="cs_timeClosed" 
                FilterControlAltText="Filter cs_timeClosed column" HeaderText="Avslutat" 
                UniqueName="cs_timeClosed" DataFormatString="{0:yy-MM-dd hh:mm}">
            </telerik:GridDateTimeColumn>
            <telerik:GridBoundColumn DataField="cs_fromIP" 
                FilterControlAltText="Filter cs_fromIP column" HeaderText="IP" 
                UniqueName="cs_fromIP">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="cs_fritext" 
                FilterControlAltText="Filter cs_fritext column" HeaderText="Fritext" 
                UniqueName="cs_fritext">
            </telerik:GridBoundColumn>
            <telerik:GridHyperLinkColumn DataTextField="cs_fromComputerName" 
                FilterControlAltText="Filter cs_fromComputerName column" HeaderText="Dator" 
                UniqueName="cs_fromComputerName">
            </telerik:GridHyperLinkColumn>
            <telerik:GridBoundColumn DataField="st_name" 
                FilterControlAltText="Filter st_name column" HeaderText="Status" 
                UniqueName="st_name">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ty_name" 
                FilterControlAltText="Filter ty_name column" HeaderText="Typ" 
                UniqueName="ty_name">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="prio" 
                FilterControlAltText="Filter prio column" HeaderText="Prio" UniqueName="prio">
            </telerik:GridBoundColumn>
            <telerik:GridDateTimeColumn DataField="nt_timePosted" 
                FilterControlAltText="Filter nt_timePosted column" HeaderText="Uppdaterad" 
                UniqueName="nt_timePosted" DataFormatString="{0:yy-MM-dd hh:mm}">
            </telerik:GridDateTimeColumn>
            <telerik:GridHyperLinkColumn DataTextField="cs_us_name" 
                FilterControlAltText="Filter cs_us_name column" HeaderText="Inlagt av" 
                UniqueName="cs_us_name">
            </telerik:GridHyperLinkColumn>
            <telerik:GridHyperLinkColumn DataTextField="adm_ad_username" 
                FilterControlAltText="Filter adm_ad_username column" HeaderText="Ansvarig" 
                UniqueName="adm_ad_username">
            </telerik:GridHyperLinkColumn>
            <telerik:GridBoundColumn DataField="maxRead" 
                FilterControlAltText="Filter maxRead column" HeaderText="maxRead" 
                UniqueName="maxRead" Visible="False">
            </telerik:GridBoundColumn>
        </Columns>
  
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
    </MasterTableView>
    <ClientSettings AllowDragToGroup="True">
    </ClientSettings>
  
<FilterMenu EnableImageSprites="False"></FilterMenu>
</telerik:RadGrid>


Page load,
dsHelpdeskG2.caseListDataTable dtCases = null;
  
if (((AdManager.UserInfo)Session[Common.userSession]).Status == AdManager.LoginStatus.User)
{
    dsHelpdeskG2TableAdapters.caseListTableAdapter taCases = new dsHelpdeskG2TableAdapters.caseListTableAdapter();
dtCases = taCases.caseListUser(((AdManager.UserInfo)Session[Common.userSession]).AnstId);
}
grCaseList.DataSource = dtCases;
grCaseList.DataBind();

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 21 Mar 2011, 10:49 AM
Hello Christian,

I am getting this error when my DataTable does not contain the field(here 'maxRead'). So please make sure that the DataTable contains the field 'maxRead' or the fieldname you have mentioned in code snippet is same as that of the fieldname in DataTable.

Hope this helps,
Princy.
0
Christian
Top achievements
Rank 1
answered on 21 Mar 2011, 11:11 AM
Hello Princy,

I have checked and re-checked, all columns are part of the datatable, maxRead and maxNote is bound to the table.

when it crashes i had a look at the drw (datarowview) and it only contains one column, the column i try to group, this might be normal since i suppose it creates a column for the grouped column but i might be wrong here, and it wont find the maxRead nor maxNote columns in the drw, please see attached images.

Regards
Christian

0
Martin
Telerik team
answered on 24 Mar 2011, 10:25 AM
Hello Christian,

I have already addressed the support ticket you have opened on the same topic. I am pasting my answer here to make it available for members of our community.

You should ensure that you are getting the correct DataItem item in your ItemDataBound event:

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem && e.Item.DataItem is DataRowView)
    {
        DataRowView drw = (DataRowView)e.Item.DataItem;
        if ((int)drw["maxRead"] != (int)drw["maxNote"])
        {
            e.Item.Font.Bold = true;
        }
    }
}

In addition I would suggest that you bind your grid through NeedDataSource event as it is especially designed for advanced features like grouping, filtering and so on.

I hope this helps.

Greetings,
Martin
the Telerik team
0
Christian
Top achievements
Rank 1
answered on 24 Mar 2011, 10:39 AM
Worked like a charm, thank you Martin.
Tags
Grid
Asked by
Christian
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Christian
Top achievements
Rank 1
Martin
Telerik team
Share this question
or