6 Answers, 1 is accepted
From the error, it is clear that there is no column/cell with the name that you used in code. This can happen if you are trying to access a cell, with the wrong name. Please check whether you typed the name correctly.
Are you using hierarchy? If yes, keep in mind that the ItemDataBound event will be raised for all items in the master and the detail table, when they are populated. Therefore, you will need to differentiate between the different items. Also, you can debug to see whether the error is thrown for master table item, or for a detail table one.
-Shinu.
Thanks I fixed it by checking the naming thing i got some names wrong.
Thanks anyway.
Hamda
<Telerik:RadGrid ID="rgdActiveBatchJobs" runat="server" AutoGenerateColumns="false"
AllowAutomaticInserts="false" AllowMultiRowSelection="true" OnItemCreated="rgdActiveBatchJobs_ItemCreated"
ShowGroupPanel="True" GridLines="none">
<PagerStyle Mode="NumericPages"></PagerStyle>
<MasterTableView AutoGenerateColumns="False" GroupLoadMode="Client" GroupsDefaultExpanded="false" >
<GroupByExpressions>
<Telerik:GridGroupByExpression>
<SelectFields>
<Telerik:GridGroupByField FieldAlias="Plan" FieldName="Plan"></Telerik:GridGroupByField>
</SelectFields>
<GroupByFields>
<Telerik:GridGroupByField FieldName="Plan"></Telerik:GridGroupByField>
</GroupByFields>
</Telerik:GridGroupByExpression>
</GroupByExpressions>
<Columns>
<Telerik:GridBoundColumn HeaderText="Active Batch Jobs" DataField="Job Name" ReadOnly="true"
Visible="true" UniqueName="Job Name">
</Telerik:GridBoundColumn>
<Telerik:GridClientSelectColumn HeaderText="Trigger" DataTextField="Trigger" UniqueName="Trigger">
</Telerik:GridClientSelectColumn>
<Telerik:GridTemplateColumn HeaderText="Status">
<ItemTemplate>
<asp:Image ID="ActiceBatchJobImageCol" runat="server" ImageUrl="" AlternateText="Not Yet started to Promote" />
</ItemTemplate>
</Telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
<ClientSettings EnableRowHoverStyle="false" AllowGroupExpandCollapse="True">
<Selecting AllowRowSelect="true" UseClientSelectColumnOnly="true"></Selecting>
</ClientSettings>
<GroupingSettings ShowUnGroupButton="true"></GroupingSettings>
</Telerik:RadGrid>
As can be seen from above I have used grouping based on a field called "Plan" in the above grid. Now from server side when I wish to access grid rows based on the plan name and the column "Job Name" I am struggling a bit.
rgdActiveBatchJobs.DataSource = dt;
rgdActiveBatchJobs.DataBind();
foreach (GridDataItem item in rgdActiveBatchJobs.MasterTableView.Items)
{
string jobName = item["Job Name"].Text;
string planName = item["Plan"].Text;
}
in the above code the jobname is coming out fine but when it runs the line string planName = item["Plan"].Text; it throws an error "Cannot find a cell bound to column name 'Plan'" Could anyone please reply how to obtain the value of the group by field for each datarow of the radgrid.
Thanks and Regards,
Gaurav Agrawal
Please try the following code snippet to get the text in GroupByField.
C#:
protected
void
RadGrid1_ItemDataBound(
object
sender, Telerik.Web.UI.GridItemEventArgs e)
{
if
(e.Item
is
GridGroupHeaderItem)
{
GridGroupHeaderItem item = (GridGroupHeaderItem)e.Item;
DataRowView groupDataRow = (DataRowView)e.Item.DataItem;
item.DataCell.Text = groupDataRow.Row.ItemArray[0].ToString();
}
}
Thanks,
Shinu.
Thank you very much. It helped me to solve my problem.
Thanks a lot..!!
Hi,
Please help me to sort out this issue :
On rad grid Item Data bound when i am trying to check for null it throw exception.
if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
{
GridDataItem dataBoundItem = e.Item as GridDataItem;
if (dataBoundItem["Payment Status"] != null)
{
hlControl.Text = e.Item.Cells[grdACHStatus.MasterTableView.GetColumn("Payment Status").OrderIndex].Text;
hlControl.ForeColor = System.Drawing.Color.Blue;
hlControl.Style.Add("text-decoration", "underline");
hlControl.Style.Add("cursor", "pointer");
}
}
If i use below code it always count this as null:
GridColumn col = grdACHStatus.MasterTableView.Columns.FindByUniqueNameSafe("Payment Status");
if (col != null)
{
}
Please suggest.