Hi. I have RadGrid with filter implemented as combo box. On Item command of GridColumnButton I update the record that changes value of the field being filtered by and rebind the grid. If before grid was filtered by the column that is updated and result contains only one record, rebind crashes the application. After record is updated, the only valid value for column "Sections" is Any Sections Not Complete.
<telerik:GridButtonColumn UniqueName="ImageButton" CommandName="MarkRecord" ButtonType="ImageButton"
ImageUrl="Content/Images/Reverse.jpg" HeaderStyle-Width="60px" Exportable="false">
</telerik:GridButtonColumn>
<telerik:GridBoundColumn UniqueName="Sections" DataField="Sections" HeaderText="Sections" HeaderStyle-Width="180px" Exportable="false">
<FilterTemplate>
<telerik:RadComboBox ID="ddlSection" runat="server" DataSource="<%#Sections %>"
DataTextField="Name" DataValueField="Name" Width="130px" AppendDataBoundItems="true"
SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("Sections").CurrentFilterValue %>'
OnClientSelectedIndexChanged="SectionsIndexChanged">
<Items>
<telerik:RadComboBoxItem Text="All" />
</Items>
</telerik:RadComboBox>
<telerik:RadScriptBlock ID="RadScriptBlock3" runat="server">
<script type="text/javascript">
function SectionsIndexChanged(sender, args) {
var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
alert(args.get_item().get_value());
tableView.filter("Sections", args.get_item().get_value(), "EqualTo");
}
</script>
</telerik:RadScriptBlock>
</FilterTemplate>
</telerik:GridBoundColumn>
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
string strNewStatus;
string btnAction;
if(e.CommandName == "Complete" || e.CommandName == "Reverse")
{
if (e.CommandName == "Complete")
{
strNewStatus = "COMPLETE";
btnAction = "Mark Complete";
}
else
{
strNewStatus = "PENDING";
btnAction = "Reverse Complete";
}
GridDataItem dataItem = e.Item as GridDataItem;
var id = (int)dataItem.OwnerTableView.DataKeyValues[dataItem.ItemIndex]["EncounterID"];
Encounter enc = Encounters.Find(i => i.EncounterID == id);
string userName = HttpContext.Current.User.Identity.Name.Replace("ROTHMAN\\", String.Empty);
string retValue;
retValue = DataAccess.UpdateVisitInfo(Convert.ToInt32(enc.tid), enc.EncounterID, enc.ECWAcct, userName, strNewStatus, enc.notes, ddlSource.SelectedValue);
if (retValue != "")
{
//handle error
e.Canceled = true;
radWindowManager.RadAlert(retValue, 280, 100, "Error", null);
return;
}
retValue = DataAccess.UpdateTracker(userName, enc.EncounterID, Convert.ToInt32(enc.ECWAcct), btnAction, strNewStatus, "", ddlSource.SelectedValue);
if (retValue != "")
{
e.Canceled = true;
radWindowManager.RadAlert(retValue, 280, 100, "Error", null);
return;
}
// refresh grid
Session["Encounters"] = null;
RadGrid1.Rebind();
}
}