Telerik RadGrid 添加/编辑行性能问题

发布于 2024-08-15 07:07:12 字数 6235 浏览 4 评论 0原文

在 Telerik RadGrid 中,用户能够添加一行并编辑现有行。看起来网格实际上强制在 UI 控件呈现在屏幕上之前发生回发。我注意到从单击按钮到出现控件的时间有一到两秒的延迟。这似乎太长了一到两秒。这是我的代码,我不太确定错误是什么。

我提前为“我的代码帖子出了什么问题”表示歉意,但这似乎是解决此问题的最简单方法。再次,我遇到了性能问题,想弄清楚如何解决它,需要调整哪些代码......

<asp:UpdatePanel ID="upPhone" runat="server">
    <contenttemplate>
            <telerik:RadGrid runat="server" ID="gridPhone" DataSourceID="dsPhone" AutoGenerateColumns="False"
                Width="100%" AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
                GridLines="None" Skin="Vista" AllowAutomaticUpdates="True" 
                ondatabound="gridPhone_DataBound" onitemdeleted="gridPhone_ItemDeleted" 
                oniteminserted="gridPhone_ItemInserted" 
                onitemupdated="gridPhone_ItemUpdated" 
                onneeddatasource="gridPhone_NeedDataSource">
                <MasterTableView DataKeyNames="phone_id" CommandItemDisplay="Top" 
                    EditMode="InPlace" AllowFilteringByColumn="False">
                    <Columns>
                        <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
                            <ItemStyle CssClass="MyImageButton" />
                        </telerik:GridEditCommandColumn>
                        <telerik:GridBoundColumn DataField="phone_id" ReadOnly="true" UniqueName="phone_id"
                            Visible="false">
                        </telerik:GridBoundColumn>
                        <telerik:GridDropDownColumn DataField="d_phone_type_id" DataSourceID="dsPhoneType"
                            UniqueName="d_phone_type_id" DataType="System.Int32" ListValueField="d_phone_type_id"
                            ListTextField="name" HeaderText="Type">
                        </telerik:GridDropDownColumn>
                        <telerik:GridTemplateColumn HeaderText="Number" SortExpression="number" UniqueName="number">
                            <ItemTemplate>
                                <asp:Label runat="server" ID="lblPhoneNumber" Text='<%# Eval("number", "{0:(###) ###-####}") %>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:TextBox ID="txtNumber" MaxLength="10" runat="server" Text='<%# Bind("number") %>'></asp:TextBox>

                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridBoundColumn DataField="description" UniqueName="description" HeaderText="Description">
                        </telerik:GridBoundColumn>
                        <telerik:GridCheckBoxColumn DataField="isprimary" UniqueName="isprimary" HeaderText="Primary"
                            DataType="System.Int16">
                        </telerik:GridCheckBoxColumn>
                        <telerik:GridButtonColumn ConfirmText="Delete this number?" ConfirmDialogType="RadWindow"
                            ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete"
                            UniqueName="DeleteColumn">
                            <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />
                        </telerik:GridButtonColumn>
                    </Columns>
                    <EditFormSettings>
                        <EditColumn UniqueName="EditCommandColumn1">
                        </EditColumn>
                    </EditFormSettings>
                </MasterTableView>
                <ClientSettings>
                    <Selecting AllowRowSelect="True" />
                </ClientSettings>
            </telerik:RadGrid>
            <asp:ObjectDataSource ID="dsPhoneType" runat="server" 
                OldValuesParameterFormatString="original_{0}" SelectMethod="GetPhoneTypes" 
                TypeName="DataAccess"></asp:ObjectDataSource>
            <asp:SqlDataSource ID="dsPhone" runat="server" ConnectionString="<%$ ConnectionStrings:TBD %>"
                DeleteCommand="DELETE FROM [phone] WHERE [phone_id] = @phone_id" InsertCommand="INSERT INTO [phone] ([person_id],[d_phone_type_id], [number], [description], [isprimary]) VALUES (@person_id,@d_phone_type_id, @number, @description, @isprimary)"
                SelectCommand="get_PhoneById" UpdateCommand="UPDATE [phone] SET [d_phone_type_id] = @d_phone_type_id, [number] = @number, [description] = @description, [isprimary] = @isprimary WHERE [phone_id] = @phone_id"
                SelectCommandType="StoredProcedure">
                <SelectParameters>
                    <asp:ControlParameter ControlID="lblID" Name="person_id" PropertyName="Text" Type="Int32" />
                </SelectParameters>
                <DeleteParameters>
                    <asp:Parameter Name="phone_id" Type="Int32" />
                </DeleteParameters>
                <UpdateParameters>
                    <asp:Parameter Name="d_phone_type_id" Type="Int32" />
                    <asp:Parameter Name="number" Type="Int64" />
                    <asp:Parameter Name="description" Type="String" />
                    <asp:Parameter Name="isprimary" Type="Boolean" />
                    <asp:Parameter Name="phone_id" Type="Int32" />
                </UpdateParameters>
                <InsertParameters>
                    <asp:ControlParameter ControlID="lblID" Name="person_id" PropertyName="Text" />
                    <asp:Parameter Name="d_phone_type_id" Type="Int32" />
                    <asp:Parameter Name="number" Type="Int64" />
                    <asp:Parameter Name="description" Type="String" />
                    <asp:Parameter Name="isprimary" Type="Boolean" />
                </InsertParameters>
            </asp:SqlDataSource>
        </contenttemplate>
</asp:UpdatePanel>

In a Telerik RadGrid, the user has the ability to add a row and edit an existing one. It appears that the grids actually force a postback to occur before the UI controls are rendered on the screen. I'm noticing a second to two seconds delay from the time the button is clicked to the time the controls appear. This seems about a second to two seconds too long. Here is my code, I'm not exactly sure what the bug is.

I apologize in advance for the "whatz wrongz with me codez post", but this seems like the easiest way to go about this one. Again, I have a performance issue and would like to figure out how to solve it in terms of what code needs to be tweaked.....

<asp:UpdatePanel ID="upPhone" runat="server">
    <contenttemplate>
            <telerik:RadGrid runat="server" ID="gridPhone" DataSourceID="dsPhone" AutoGenerateColumns="False"
                Width="100%" AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
                GridLines="None" Skin="Vista" AllowAutomaticUpdates="True" 
                ondatabound="gridPhone_DataBound" onitemdeleted="gridPhone_ItemDeleted" 
                oniteminserted="gridPhone_ItemInserted" 
                onitemupdated="gridPhone_ItemUpdated" 
                onneeddatasource="gridPhone_NeedDataSource">
                <MasterTableView DataKeyNames="phone_id" CommandItemDisplay="Top" 
                    EditMode="InPlace" AllowFilteringByColumn="False">
                    <Columns>
                        <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
                            <ItemStyle CssClass="MyImageButton" />
                        </telerik:GridEditCommandColumn>
                        <telerik:GridBoundColumn DataField="phone_id" ReadOnly="true" UniqueName="phone_id"
                            Visible="false">
                        </telerik:GridBoundColumn>
                        <telerik:GridDropDownColumn DataField="d_phone_type_id" DataSourceID="dsPhoneType"
                            UniqueName="d_phone_type_id" DataType="System.Int32" ListValueField="d_phone_type_id"
                            ListTextField="name" HeaderText="Type">
                        </telerik:GridDropDownColumn>
                        <telerik:GridTemplateColumn HeaderText="Number" SortExpression="number" UniqueName="number">
                            <ItemTemplate>
                                <asp:Label runat="server" ID="lblPhoneNumber" Text='<%# Eval("number", "{0:(###) ###-####}") %>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:TextBox ID="txtNumber" MaxLength="10" runat="server" Text='<%# Bind("number") %>'></asp:TextBox>

                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridBoundColumn DataField="description" UniqueName="description" HeaderText="Description">
                        </telerik:GridBoundColumn>
                        <telerik:GridCheckBoxColumn DataField="isprimary" UniqueName="isprimary" HeaderText="Primary"
                            DataType="System.Int16">
                        </telerik:GridCheckBoxColumn>
                        <telerik:GridButtonColumn ConfirmText="Delete this number?" ConfirmDialogType="RadWindow"
                            ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete"
                            UniqueName="DeleteColumn">
                            <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />
                        </telerik:GridButtonColumn>
                    </Columns>
                    <EditFormSettings>
                        <EditColumn UniqueName="EditCommandColumn1">
                        </EditColumn>
                    </EditFormSettings>
                </MasterTableView>
                <ClientSettings>
                    <Selecting AllowRowSelect="True" />
                </ClientSettings>
            </telerik:RadGrid>
            <asp:ObjectDataSource ID="dsPhoneType" runat="server" 
                OldValuesParameterFormatString="original_{0}" SelectMethod="GetPhoneTypes" 
                TypeName="DataAccess"></asp:ObjectDataSource>
            <asp:SqlDataSource ID="dsPhone" runat="server" ConnectionString="<%$ ConnectionStrings:TBD %>"
                DeleteCommand="DELETE FROM [phone] WHERE [phone_id] = @phone_id" InsertCommand="INSERT INTO [phone] ([person_id],[d_phone_type_id], [number], [description], [isprimary]) VALUES (@person_id,@d_phone_type_id, @number, @description, @isprimary)"
                SelectCommand="get_PhoneById" UpdateCommand="UPDATE [phone] SET [d_phone_type_id] = @d_phone_type_id, [number] = @number, [description] = @description, [isprimary] = @isprimary WHERE [phone_id] = @phone_id"
                SelectCommandType="StoredProcedure">
                <SelectParameters>
                    <asp:ControlParameter ControlID="lblID" Name="person_id" PropertyName="Text" Type="Int32" />
                </SelectParameters>
                <DeleteParameters>
                    <asp:Parameter Name="phone_id" Type="Int32" />
                </DeleteParameters>
                <UpdateParameters>
                    <asp:Parameter Name="d_phone_type_id" Type="Int32" />
                    <asp:Parameter Name="number" Type="Int64" />
                    <asp:Parameter Name="description" Type="String" />
                    <asp:Parameter Name="isprimary" Type="Boolean" />
                    <asp:Parameter Name="phone_id" Type="Int32" />
                </UpdateParameters>
                <InsertParameters>
                    <asp:ControlParameter ControlID="lblID" Name="person_id" PropertyName="Text" />
                    <asp:Parameter Name="d_phone_type_id" Type="Int32" />
                    <asp:Parameter Name="number" Type="Int64" />
                    <asp:Parameter Name="description" Type="String" />
                    <asp:Parameter Name="isprimary" Type="Boolean" />
                </InsertParameters>
            </asp:SqlDataSource>
        </contenttemplate>
</asp:UpdatePanel>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如梦亦如幻 2024-08-22 07:07:12

只需检查几件事:

您是否重复 gridPhone_NeedDataSource 事件、ItemUpdated、Deleted 和 Inserted 事件以及本机 Rad Grid 绑定行为中的绑定行为(通过使用 asp: SqlDataSource 控件)? 查看您的代码隐藏以了解您是否是这样会很有用。

网格中有多少条记录?我发现网格中是否有大量项目并且打开了一些高级功能(我注意到您已经进行了行选择启用)网格逐渐停止。

如果这些都不起作用/不适用于您的情况,那么可能值得检查 性能部分

Just a couple of things to check:

Are you duplicating the bind behaviour in the gridPhone_NeedDataSource event, your ItemUpdated, Deleted and Inserted events, and the native Rad Grid binding behviour (by using a asp:SqlDataSource control)? It would be useful to see your code-behind to see if you are or not.

How many records do you have in the grid? I find if I have a large number of items in the Grid and have some of the advanced features turned on (I've noticed you've got row selecting enabled) the grid grinds to a halt.

If none of these work/apply to your situation then it maybe worth checking the performance section of their site.

烟织青萝梦 2024-08-22 07:07:12

我发现您正在使用 DataSourceID="dsPhone"onneeddatasource="gridPhone_NeedDataSource"

不确定您是否需要两者。还要确保您不在代码中的其他位置(page_Load或任何其他位置)执行 DataBind() ,因为您已经将 OnNeedDataSource 事件附加到网格

I am seeing that you are using DataSourceID="dsPhone" and onneeddatasource="gridPhone_NeedDataSource"

not sure if you need both. Also make sure you dont do a DataBind() else where in your code (page_Load or any other place) since you already have OnNeedDataSource event attached to the grid

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文