Telerik RadGrid更新命令未触发

时间:2016-08-02 22:22:17

标签: c# asp.net webforms telerik

所以,我有一个RadGrid的典型编辑安排正在运作......现在还没有。永远不要触发UpdateCommand事件,在那里设置一个断点并且没有到达它。让我发疯,因为它工作得很好,我无法想到我所做的任何会导致它的事情。当我单击编辑时,窗体打开就好了,取消按钮工作,但更新命令永远不会触发。 在网格中我有:

OnUpdateCommand="pendingVehiclesRadGrid_UpdateCommand" 

And in my code behind I have:

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

看起来很简单,但正如我所说......没什么。如果有新眼睛的人可以提出建议,我将一如既往地深表感激。

编辑以添加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>

2 个答案:

答案 0 :(得分:1)

我试图重建你的例子并且它有效:

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>

代码隐藏:

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)
{

}

正如您所看到的,我删除了一些不必要的标记,但这不是问题的来源。我还必须删除RadComboBox中的EditItemTemplate,因为我无法使用LinqDataSource1

但要明确:我不知道为什么它不适用于您,但我希望这可以帮助您跟踪问题。

尝试对RadComboBox发表评论。看看这是否是问题来源。如果没有,你可能会在你的代码中犯任何错误,也许在数据绑定本身。

如果无法跟踪问题,请尝试在自己的解决方案中隔离问题。使用硬编码数据(如我的例子)将其钉死。如果问题仍然存在,请发布测试解决方案中的所有代码或共享解决方案本身不带 Telerik组件(!)

答案 1 :(得分:0)

@modiX好的...再次感谢你的帮助。我还没有弄明白这个问题,但是在对抗它两天之后,我意识到,在某一点上,这完成了所有工作,也许在我在表格上做的所有其他工作的某个地方,我打破了它并没有实现它直到为时已晚。因此,我开始逐个删除三个网格中的每个网格及其代码,并将它们粘贴到一个全新的页面中。并且...他们工作。

不知道什么“特征”导致他们打破,但我愿意称之为胜利并继续...更谨慎;)

再次感谢你的时间和善意的帮助!