asp.net Telerik RadGrid更新命令未启动

mftmpeh8  于 2023-02-10  发布在  .NET
关注(0)|答案(3)|浏览(103)

所以,我有一个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>
e0bqpujr

e0bqpujr1#

我试着重新构建你的例子,它起作用了:
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组件(!)

hjqgdpho

hjqgdpho2#

@modiX好的...,,.再次真诚地感谢你的帮助。我还没有弄清楚这个问题,但是在我的头撞了两天之后,我意识到,在某个时候,它做了所有的工作,也许在我做的所有其他工作的某个地方,我打破了它,直到为时已晚才意识到。所以,我开始一次一个地剪下三个网格和它们后面的代码,然后把它们粘贴到一个新的页面上。
不知道是什么“功能”导致他们打破,但我愿意称之为一个胜利,并继续前进...更谨慎;)
再次感谢您的时间和善意的帮助!

wpcxdonn

wpcxdonn3#

老问题,但我一直在挣扎,并有一些没有意义,但似乎工作。
我在RadGrid下添加了<ClientEvents OnRowDeleting="void 0" />ClientSettings,看起来效果不错,它还保持了RadGrid的正常大小;它被切成了两半,没有明显的原因,滚动条在一半。
这应该是在删除记录时触发Javascript,但我不需要它实际这样做。因此,void 0使它什么也不做。
我没有解释为什么它会像现在这样工作,这很令人沮丧,但它至少现在工作得更好了。

相关问题