代码之家  ›  专栏  ›  技术社区  ›  RSolberg

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

  •  3
  • RSolberg  · 技术社区  · 15 年前

    在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>
    
    2 回复  |  直到 15 年前
        1
  •  1
  •   Robert W    15 年前

    只需检查几件事:

    查看您的代码以了解您是否在后面是很有用的。

    我发现,如果网格中有大量项目,并且启用了一些高级功能(我注意到您启用了行选择),那么网格将停止运行。

    如果这些都不适用于你的情况,那么可能值得检查 performance section

        2
  •  1
  •   ram    15 年前

    我看到你正在使用 DataSourceID="dsPhone" onneeddatasource="gridPhone_NeedDataSource"

    不确定你是否两者都需要。另外,请确保不要在代码的其他位置(加载页面或任何其他位置)执行DataBind(),因为您已经将OnnedDataSource事件附加到网格

    推荐文章