I am working with a Telerik grid that has a details table for each row. The row is of type NominationTypeClass
and the rows in the details table are of type Nomination
. This setup means that for each nomination type, there is a list of nominations. The code for the grid looks like this:
<telerik:RadGrid
AllowPaging="true"
AllowSorting="true"
AutoGenerateColumns="false"
GridLines="None"
ID="rgMyNominations"
OnDetailTableDataBind="rgMyNominations_DetailTableDataBind"
OnItemDataBound="rgMyNominations_ItemDataBound"
OnNeedDataSource="rgMyNominations_NeedDataSource"
OnUpdateCommand="rgMyNominations_UpdateCommand"
PageSize="5"
runat="server"
ShowHeader="false"
ShowStatusBar="true">
<MasterTableView DataKeyNames="NominationTypeID" HierarchyDefaultExpanded="true" Width="100%">
<Columns>
<telerik:GridTemplateColumn>
<ItemTemplate>
<b><asp:Label ID="lblNominationType" runat="server" Text='<%# DataBinder.Eval( Container, "DataItem.NominationType") %>' /></b>
</ItemTemplate>
<ItemStyle Width="100%" />
</telerik:GridTemplateColumn>
</Columns>
<NoRecordsTemplate>No Nomination Types.</NoRecordsTemplate>
<DetailTables>
<telerik:GridTableView PageSize="5" Name="Nominations" GridLines="None" Width="100%" ShowHeader="true" DataKeyNames="NominationID">
<Columns>
<telerik:GridTemplateColumn HeaderText="Person / Team">
<ItemTemplate>
<asp:Label ID="lblName" runat="server" Text='<%# GetName(DataBinder.Eval(Container, "DataItem")) %>' />
</ItemTemplate>
<ItemStyle VerticalAlign="Top" Width="20%" />
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Date Nominated">
<ItemTemplate>
<asp:Label ID="lblNominationDate" runat="server" Text='<%# FormatDate(DataBinder.Eval(Container, "DataItem.NominationDate")) %>' />
</ItemTemplate>
<ItemStyle VerticalAlign="Top" Width="14%" />
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Action" UniqueName="Action_Column">
<ItemTemplate>
<b><asp:HyperLink ID="hlEdit" runat="server" Text="Edit" /></b><br />
<b>
<asp:LinkButton
CausesValidation="false"
CommandName="Update"
ID="lbWithdrawnStatus"
runat="server"
Text="Withdraw"
OnClientClick="javascript:return ConfirmWithdrawnStatusChange();" />
</b>
</ItemTemplate>
<ItemStyle VerticalAlign="Top" Width="7%" />
</telerik:GridTemplateColumn>
</Columns>
<NoRecordsTemplate>No Nominations.</NoRecordsTemplate>
</telerik:GridTableView>
</DetailTables>
</MasterTableView>
<ClientSettings AllowExpandCollapse="true"></ClientSettings>
</telerik:RadGrid>
This is how I populate my rows:
protected void rgMyNominations_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
try
{
if (!e.IsFromDetailTable)
{
rgMyNominations.DataSource = GetNominationTypes();
}
}
catch (Exception ex)
{
// Handle exceptions
}
}
And here is how I populate the details table:
protected void rgMyNominations_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e)
{
try
{
GridDataItem gridDataItem = (GridDataItem)e.DetailTableView.ParentItem;
if (e.DetailTableView.Name == "Nominations")
{
int nominationTypeID = int.Parse(gridDataItem.GetDataKeyValue("NominationTypeID").ToString());
List<Nomination> nominations = new List<Nomination>();
// For each nomination type, add the nomination
foreach (Nomination n in myNominationsList)
{
if (n.NominationType.NominationTypeID == nominationTypeID)
{
nominations.Add(n);
}
}
e.DetailTableView.DataSource = nominations;
}
}
catch (Exception ex)
{
// Handle exceptions
}
}
In the action column, there is a link labeled Withdrawn. When clicked, a JavaScript confirm box appears with options Yes or No. If Yes is selected, the nomination status is updated to withdrawn. After this update, the grid should refresh to reflect the updated status. I used the grid's update command to trigger the JavaScript confirmation box. It does update, but I'm not sure if it's the correct approach.
protected void rgMyNominations_UpdateCommand(object source, GridCommandEventArgs e)
{
try
{
StatusManager.InsertStatus( /* required parameters */ );
// Refresh grid
rgMyNominations.DataSource = GetNominationTypes();
rgMyNominations.DataBind();
}
catch (Exception ex)
{
// Handle exceptions
}
}
However, the grid binding doesn't work properly after the status update. The grid row is of type NominationTypeClass
and the details table is of type Nomination
. While debugging, I found that when setting the data source for each, it is correct. But during rendering, the error message shows that NominationDate is not a property of NominationTypeClass
, which is incorrect. NominationDate is a property of Nomination. It seems like the datasources are being overridden. Any suggestions on how to solve this issue or any online samples for reference would be greatly appreciated.