Telerik RadGrid Paging - 重复记录和粘贴按钮

发布于 2024-12-09 01:39:45 字数 2705 浏览 0 评论 0原文

我最近开始使用 ASP.Net 和 Telerik 的 RadGrid,但遇到了一个问题:

我的 RadGrid 对象位于 Page 对象(具有脚本管理器)内的自定义控件对象内的 UserControl 对象内。

我在所述自定义控件中有几个 UserControl,每个都包含 RadGrid 对象的标记,如下所示:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="AreaListRadGrid.ascx.cs" Inherits="WebControls.AreaListRadGrid" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" assembly="Telerik.Web.UI" %>

<telerik:RadAjaxPanel runat="server" ID="radAjaxPanel" 
            EnableAJAX="true" LoadingPanelID="radAjaxLoadingPanel">
    <telerik:RadGrid AllowPaging="true" AutoGenerateColumns="false" DataSourceID="gridData" EnableViewState="true" GridLines="None" ID="radGrid" runat="server">
        <PagerStyle Mode="NumericPages" />
        <MasterTableView>
            <Columns>
                <telerik:GridBoundColumn DataField="ColA" HeaderText="A" />
                <telerik:GridBoundColumn DataField="ColB" HeaderText="B" />
                <telerik:GridBoundColumn DataField="ColC" HeaderText="C" />
                <telerik:GridBoundColumn DataField="ColD" HeaderText="D" />
                <telerik:GridBoundColumn DataField="ColE" HeaderText="E" />
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>
</telerik:RadAjaxPanel>

 <asp:ObjectDataSource  ID="gridData" runat="server"
                        SelectMethod="GetData"
                        SelectCountMethod="GetDataCount"
                        OnObjectCreating="dataObjectCreating"
                        TypeName="AreaListRadGrid">
</asp:ObjectDataSource>

<telerik:RadAjaxLoadingPanel runat="server" ID="radAjaxLoadingPanel">
        Loading please wait....
</telerik:RadAjaxLoadingPanel>

我已将列和命名空间的名称更改为非项目特定的名称,但网格会加载。

由于它位于自定义控件中,因此实例化如下:

var view = (AreaListRadGrid)this.TemplateControl.LoadControl(".\\WebControls\\AreaListRadGrid.ascx");
view.DataSource = dataSet;
areaCenterMiddle.Controls.Add(view);
view.RadGrid.Rebind();

dataSet 变量的类型为 System.Data.DataSet

因此,当我运行该网站时,会出现 Rad Grid。我有一个包含 4 行的网格,其中 3 行位于第 1 页,最后一行位于第 2 页。 初始 radgrid 第 2 页点击后 当我点击第 2 页时,一切都按预期发生。页面按钮的样式发生变化,第 1 页中的行被删除,第 2 页中的行添加到网格中。伟大的!接下来发生的事情是我不明白的:

再次单击第 1 页时,第 2 页按钮的样式不会更改(因此仍然像单击一样)并且第 2 行和第 3 行出现在网格上,但是第一行是第 2 页上的行。

re-visit to page 1

看起来好像是第 2 页加载第 1 页时未清除,但我不确定这是为什么或如何发生。有人对我做错了什么有任何想法吗?

非常感谢您的帮助。

干杯,

罗布

I've recently started using ASP.Net and Telerik's RadGrid but have ran into a problem:

My RadGrid object is within a UserControl object within a Custom Control object within a Page object (which has a script manager).

I have several UserControls within said Custom Control, each containing the markup for a RadGrid object as below:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="AreaListRadGrid.ascx.cs" Inherits="WebControls.AreaListRadGrid" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" assembly="Telerik.Web.UI" %>

<telerik:RadAjaxPanel runat="server" ID="radAjaxPanel" 
            EnableAJAX="true" LoadingPanelID="radAjaxLoadingPanel">
    <telerik:RadGrid AllowPaging="true" AutoGenerateColumns="false" DataSourceID="gridData" EnableViewState="true" GridLines="None" ID="radGrid" runat="server">
        <PagerStyle Mode="NumericPages" />
        <MasterTableView>
            <Columns>
                <telerik:GridBoundColumn DataField="ColA" HeaderText="A" />
                <telerik:GridBoundColumn DataField="ColB" HeaderText="B" />
                <telerik:GridBoundColumn DataField="ColC" HeaderText="C" />
                <telerik:GridBoundColumn DataField="ColD" HeaderText="D" />
                <telerik:GridBoundColumn DataField="ColE" HeaderText="E" />
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>
</telerik:RadAjaxPanel>

 <asp:ObjectDataSource  ID="gridData" runat="server"
                        SelectMethod="GetData"
                        SelectCountMethod="GetDataCount"
                        OnObjectCreating="dataObjectCreating"
                        TypeName="AreaListRadGrid">
</asp:ObjectDataSource>

<telerik:RadAjaxLoadingPanel runat="server" ID="radAjaxLoadingPanel">
        Loading please wait....
</telerik:RadAjaxLoadingPanel>

I've changed the names of columns and namespaces to something non-project specific, but the grid loads.

As it's in a Custom Control, it is instantiated as follows:

var view = (AreaListRadGrid)this.TemplateControl.LoadControl(".\\WebControls\\AreaListRadGrid.ascx");
view.DataSource = dataSet;
areaCenterMiddle.Controls.Add(view);
view.RadGrid.Rebind();

the dataSet variable is of type System.Data.DataSet.

So, when I run this website, the Rad Grid appears. I've got a grid with 4 rows, 3 of which are on page 1 and the final row is on page 2.
initial radgrid
after page 2 click
When I click page 2, everything happens as expected. The styling for for page buttons change, and the rows from page 1 are removed, with the row from page 2 added to the grid. Great! What happens next is what I don't understand:

When page 1 is clicked again, the styling for the page 2 button dosn't change (so it's still as if it's clicked) and rows 2 and 3 appear on the grid, but the first row is the row which was on page 2.

re-visit to page 1

it seems as if page 2 is not clearing when page 1 is loaded, I'm not sure why or how this is, though. Anyone got any ideas to what I'm doing incorrectly?

Would really appreciate your help.

Cheers,

Rob

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

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

发布评论

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

评论(2

指尖微凉心微凉 2024-12-16 01:39:45

我确信您现在已经弄清楚了这一点,但我想知道这是否是未使用网格数据源设置 NeedDataSource 属性的副作用?

将其添加到前端的 RadGrid 控件。

OnNeedDataSource="radGrid_NeedDataSource"

并在后面的代码中处理它。

<块引用>

受保护的void radGrid_NeedDataSource(对象发送者,
GridNeedDataSourceEventArgs e) {
view.RadGrid.DataSource = gridData; }

I'm sure you've got this figured out by now, but I'm wondering if this is a side effect of not setting the NeedDataSource property with the grid datasource?

add this to RadGrid control on the front end.

OnNeedDataSource="radGrid_NeedDataSource"

and handle it in code behind.

protected void radGrid_NeedDataSource(object sender,
GridNeedDataSourceEventArgs e) {
view.RadGrid.DataSource = gridData; }

一腔孤↑勇 2024-12-16 01:39:45

加载时,您不需要向网格提供数据集。需要时,使用您在设计中设置的 DataSourceID 检索数据集。

删除“view.DataSource = dataSet;”重新绑定功能和一切都应该按预期工作。

You do not need to provide the dataset to the grid when loaded. The dataset is retrieved using the DataSourceID you have set in design, when required.

Remove "view.DataSource = dataSet;" and the rebind function and everything should work as expected.

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