PaulBinCT2 PaulBinCT2 - 4 months ago 89
ASP.NET (C#) Question

Telerik RadGrid Update Command not firing

So, I have a RadGrid with a typical edit arrangement that was working... and now isn't. Never firing the UpdateCommand event, set a breakpoint there and it's not being reached. Making me crazy because it had been working just fine and I can't think of anything I've done that would cause it. When I click edit, the form opens just fine, the cancel button works but the update command never fires.
In the grid I have:

OnUpdateCommand="pendingVehiclesRadGrid_UpdateCommand"

And in my code behind I have:

protected void pendingVehiclesRadGrid_UpdateCommand(object source, GridCommandEventArgs e)
{
blah blah
}


Seems pretty straightforward but as I say... nothing. I'd be, as always, deeply grateful if someone with fresh eyes can make a suggestion.

Edit to add XML:

<telerik:RadGrid ID="pendingVehiclesRadGrid" runat="server" AutoGenerateColumns="False"
CellSpacing="0" GridLines="None" AllowPaging="True"
DataMember="ID"
onneeddatasource="pendingVehiclesRadGrid_NeedDataSource"
OnUpdateCommand="pendingVehiclesRadGrid_UpdateCommand" PageSize="20"
onitemcommand="pendingVehiclesRadGrid_ItemCommand" >
<MasterTableView DataKeyNames="status,charity,make,model,year,vin,date,id,salePrice,bid,note"
EditMode="EditForms">

<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>

<RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>

<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>

<Columns>
<telerik:GridButtonColumn CommandName="History" Text="History" UniqueName="detailBtn" HeaderText="History" HeaderButtonType="PushButton" AutoPostBackOnFilter="True">
</telerik:GridButtonColumn>
<telerik:GridBoundColumn HeaderText="Charity" ItemStyle-Width="140px" FilterControlAltText="Filter column2 column"
UniqueName="column3" DataType="System.String" DataField="charity" ReadOnly="True">
<ItemStyle Width="140px"></ItemStyle>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="VIN" ItemStyle-Width="140px" FilterControlAltText="Filter column6 column"
UniqueName="column7" DataType="System.String" DataField="vin" >
<ItemStyle Width="140px"></ItemStyle>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Year" ItemStyle-Width="140px" FilterControlAltText="Filter column2 column"
UniqueName="column2" DataType="System.Int32" DataField="year">
<ItemStyle Width="140px"></ItemStyle>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Make" ItemStyle-Width="140px" FilterControlAltText="Filter column column"
UniqueName="column" DataType="System.String" DataField="make">
<ItemStyle Width="140px"></ItemStyle>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Model" ItemStyle-Width="140px" FilterControlAltText="Filter column1 column"
UniqueName="column1" DataType="System.String" DataField="model">
<ItemStyle Width="140px"></ItemStyle>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Last Update" ItemStyle-Width="140px" FilterControlAltText="Filter column1 column"
UniqueName="column5" DataType="System.DateTime" DataField="date" ReadOnly="True">
<ItemStyle Width="140px"></ItemStyle>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Min. Bid" ItemStyle-Width="140px" FilterControlAltText="Filter column1 column"
UniqueName="column8" DataType="System.Decimal" DataField="bid" DataFormatString="{0:C}" >
<ItemStyle Width="140px"></ItemStyle>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Sale Price" ItemStyle-Width="140px" FilterControlAltText="Filter column1 column"
UniqueName="column6" DataType="System.Decimal" DataField="salePrice" DataFormatString="{0:C}" Display="False">
<ItemStyle Width="140px"></ItemStyle>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Notes" ItemStyle-Width="140px" FilterControlAltText="Filter column1 column"
UniqueName="unsoldNotesColumn" DataType="System.String" DataField="note" Display="True">
<ItemStyle Width="140px"></ItemStyle>
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn HeaderText="Latest Status" ItemStyle-Width="240px">


<ItemTemplate>

<%#DataBinder.Eval(Container.DataItem, "Status")%>

</ItemTemplate>


<EditItemTemplate>

<telerik:RadComboBox RenderMode="Lightweight" runat="server" ID="pendingVehiclesRadGridupdateComboBox" DataTextField="Status"

DataValueField="ID" DataSourceID="LinqDataSource1" >

</telerik:RadComboBox>

</EditItemTemplate>


<ItemStyle Width="240px"></ItemStyle>


</telerik:GridTemplateColumn>

<telerik:GridEditCommandColumn FooterText="EditCommand footer" UniqueName="pendingVehiclesRadGridEditCommandColumn"

HeaderText="Edit" HeaderStyle-Width="100px" UpdateText="Update">

<HeaderStyle Width="100px"></HeaderStyle>

</telerik:GridEditCommandColumn>



</Columns>

<EditFormSettings EditColumn-DataType="System.String">
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
</MasterTableView>

<FilterMenu EnableImageSprites="False"></FilterMenu>
</telerik:RadGrid>

Answer

I've tried to reconstruct your example and it worked:

ASPX:

<telerik:RadGrid ID="pendingVehiclesRadGrid" runat="server" AutoGenerateColumns="False"
    CellSpacing="0" GridLines="None" AllowPaging="True"
    DataMember="ID"
    OnNeedDataSource="pendingVehiclesRadGrid_NeedDataSource"
    OnUpdateCommand="pendingVehiclesRadGrid_UpdateCommand" PageSize="20"
    OnItemCommand="pendingVehiclesRadGrid_ItemCommand">
    <MasterTableView DataKeyNames="status,charity,make,model,year,vin,date,id,salePrice,bid,note"
        EditMode="EditForms">

        <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>

        <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column" HeaderStyle-Width="20px" />

        <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column" HeaderStyle-Width="20px" />

        <Columns>
            <telerik:GridButtonColumn CommandName="History" Text="History" UniqueName="detailBtn" HeaderText="History" HeaderButtonType="PushButton" AutoPostBackOnFilter="True" />
            <telerik:GridBoundColumn HeaderText="Charity" ItemStyle-Width="140px" FilterControlAltText="Filter column2 column" UniqueName="column3" DataType="System.String" DataField="charity" ReadOnly="True" />
            <telerik:GridBoundColumn HeaderText="VIN" ItemStyle-Width="140px" FilterControlAltText="Filter column6 column" UniqueName="column7" DataType="System.String" DataField="vin" />
            <telerik:GridBoundColumn HeaderText="Year" ItemStyle-Width="140px" FilterControlAltText="Filter column2 column" UniqueName="column2" DataType="System.Int32" DataField="year" />
            <telerik:GridBoundColumn HeaderText="Make" ItemStyle-Width="140px" FilterControlAltText="Filter column column" UniqueName="column" DataType="System.String" DataField="make" />
            <telerik:GridBoundColumn HeaderText="Model" ItemStyle-Width="140px" FilterControlAltText="Filter column1 column" UniqueName="column1" DataType="System.String" DataField="model" />
            <telerik:GridBoundColumn HeaderText="Last Update" ItemStyle-Width="140px" FilterControlAltText="Filter column1 column" UniqueName="column5" DataType="System.DateTime" DataField="date" ReadOnly="True" />
            <telerik:GridBoundColumn HeaderText="Min. Bid" ItemStyle-Width="140px" FilterControlAltText="Filter column1 column" UniqueName="column8" DataType="System.Decimal" DataField="bid" DataFormatString="{0:C}" />
            <telerik:GridBoundColumn HeaderText="Sale Price" ItemStyle-Width="140px" FilterControlAltText="Filter column1 column" UniqueName="column6" DataType="System.Decimal" DataField="salePrice" DataFormatString="{0:C}" Display="False" />
            <telerik:GridBoundColumn HeaderText="Notes" ItemStyle-Width="140px" FilterControlAltText="Filter column1 column" UniqueName="unsoldNotesColumn" DataType="System.String" DataField="note" Display="True" />
            <telerik:GridTemplateColumn HeaderText="Latest Status" ItemStyle-Width="240px">
                <ItemTemplate>
                    <%#DataBinder.Eval(Container.DataItem, "Status")%>
                </ItemTemplate>
                <EditItemTemplate>
                    <%-- I have to outcomment this, because I don't have any LinqDataSource1 available --%>
                    <%--<telerik:RadComboBox RenderMode="Lightweight" runat="server" ID="pendingVehiclesRadGridupdateComboBox" DataTextField="Status"
                        DataValueField="ID" DataSourceID="LinqDataSource1">
                    </telerik:RadComboBox>--%>
                </EditItemTemplate>
            </telerik:GridTemplateColumn>

            <telerik:GridEditCommandColumn FooterText="EditCommand footer" UniqueName="pendingVehiclesRadGridEditCommandColumn" HeaderText="Edit" HeaderStyle-Width="100px" UpdateText="Update" />
        </Columns>

        <EditFormSettings EditColumn-DataType="System.String">
            <EditColumn FilterControlAltText="Filter EditCommandColumn column" />
        </EditFormSettings>
    </MasterTableView>

    <FilterMenu EnableImageSprites="False" />
</telerik:RadGrid>

CODE-BEHIND:

protected void pendingVehiclesRadGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    this.pendingVehiclesRadGrid.DataSource = new List<object> {
        new {
            id = 1,
            charity = "charity1",
            vin = "vin1",
            year = 2015,
            make = "make1",
            model = "model1",
            date = DateTime.Now.AddYears(-1),
            bid = (decimal)12000.00,
            salePrice = (decimal)14469.95,
            note = "a new car",
            Status = "NOT SOLD"
        },
        new {
            id = 2,
            charity = "charity2",
            vin = "vin2",
            year = 1967,
            make = "make2",
            model = "model2",
            date = DateTime.Now,
            bid = (decimal)14000.00,
            salePrice = (decimal)19469.95,
            note = "an oldtimer",
            Status = "NOT SOLD"
        }
    };
}

protected void pendingVehiclesRadGrid_UpdateCommand(object sender, GridCommandEventArgs e)
{
    Console.WriteLine("This will be reached!"); // I've put the breakpoint here
}

protected void pendingVehiclesRadGrid_ItemCommand(object sender, GridCommandEventArgs e)
{

}

As you can see I've removed some unnecessary markup, but this was not the problem source. I also had to remove the RadComboBox in your EditItemTemplate, because I cannot use the LinqDataSource1.

But to be clear: I don't know why it's not working at you, but I hope this will help you to track the issue.

Try to out-comment the RadComboBox at you, too. See if this is the problem source. If not, you might do any mistake in your code behind, maybe on the data binding itself.

If you cannot track the problem, try to isolate the problem in an own solution. Nail it down by using hard coded data (like on my example). If the problem persists, post all the code from your test solution or share the solution itself without the Telerik components (!)

Comments