【问题标题】:Telerik RadGrid Update Command not firingTelerik RadGrid 更新命令未触发
【发布时间】:2016-12-08 10:56:39
【问题描述】:

所以,我有一个具有典型编辑安排的 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>

【问题讨论】:

  • 请显示您的 RadGrid 的整个 XAML。我认为您的命令按钮有问题。
  • @modiX 我是新来的……如何将整个内容发布到 cmets 中?对不起:(
  • @PaulBinCT2 您可以编辑您的问题,而不是将其放入 cmets
  • 要检查的事项:1) 您正确使用了 NeedDataSource,并且您没有在代码中的其他任何地方手动绑定 RadGrid 2) 您的 RadGrid 标记是正确的
  • @Scotty 我当然可以检查,但它会导致更新命令根本不触发吗?

标签: c# asp.net webforms telerik


【解决方案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)
{

}

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

但要明确一点:我不知道为什么它对你不起作用,但我希望这能帮助你跟踪问题。

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

如果您无法跟踪问题,请尝试在自己的解决方案中隔离问题。通过使用硬编码数据(如我的示例)将其确定下来。如果问题仍然存在,请发布您的测试解决方案中的所有代码或共享解决方案本身没有 Telerik 组件 (!)

【讨论】:

  • 非常感谢...我知道您在帮助我方面投入了多少时间!我要解决这个问题,看看问题是否出在组合框中。我对此完全感到困惑,特别是因为它最初确实有效,而且我想不出我所做的任何改变都可以解释这一点。我会及时向大家发布!再次感谢... :)
  • 所以我担心我的速度很快。我尝试注释掉组合框,即使在我尝试在整个过程中查找和注释掉对组合框的引用之后,它也会创建关于在空对象上设置属性的各种异常。我尝试添加一个下拉列表,但“似乎”没有解决问题。我真的为此绞尽脑汁……还有其他提示/建议吗?无论如何感谢您的帮助!
【解决方案2】:

@modiX 好的...再次真诚地感谢您的帮助。我还没有弄清楚这个问题,但是在用头撞了两天之后,我意识到在某一时刻,这一切都奏效了,也许在我在表格上所做的所有其他工作中的某个地方,我把它弄坏了,但没有直到为时已晚才意识到这一点。因此,我开始一次剪切三个网格中的每一个及其后面的代码,并将它们粘贴到一个新的页面中。而且......他们工作。

不知道是什么“功能”导致它们崩溃,但我愿意称之为胜利并继续前进……更谨慎;)

再次感谢您的宝贵时间和热心帮助!

【讨论】:

  • 这不应该是一个答案,它应该只是对我的回答的评论,因为您无法为您的案例提供任何解决方案。不管怎样,你解决得很好,不过,神奇地消失的问题让我很紧张,因为它们随时可以回来,因为你不知道是什么导致它们出现。我建议您的团队使用颠覆控制软件来轻松跟踪更改。不客气! :)
  • @modiX 我同意你的所有观点......我只输入它作为答案,因为“案件已结案”。再次...谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-08
相关资源
最近更新 更多