在Gridview Pager中动态添加页面大小下拉列表

发布于 2024-11-15 22:36:58 字数 1664 浏览 4 评论 0原文

我有一个 Gridview,必须在运行时在寻呼机行添加下拉列表。我在 Gridview RowCreated 上添加了以下代码。

protected void gv_transaction_RowCreated(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.Pager)
    {
        using (DropDownList ddlpagesize = new DropDownList())
        {
            ddlpagesize.Items.Add("25");
            ddlpagesize.Items.Add("50");
            ddlpagesize.Items.Add("75");
            ddlpagesize.Items.Add("100");
            ddlpagesize.Items.Add("150");
            ddlpagesize.Items.Add("200");
            ddlpagesize.AutoPostBack = true;
            ddlpagesize.Items.FindByText(gv_transaction.PageSize.ToString()).Selected = true;
            ddlpagesize.SelectedIndexChanged += ddlpagesize_SelectedIndexChanged;
            using (Table tbl = (Table)e.Row.Cells[0].Controls[0])
            {
                using (TableCell cell = new TableCell())
                {
                    cell.Controls.Add(new LiteralControl("<b>Page Size: </b>"));
                    cell.Controls.Add(ddlpagesize);
                    tbl.Rows[0].Cells.AddAt(0, cell);
                }
            }
        }
    }
}
protected void ddlpagesize_SelectedIndexChanged(object sender, EventArgs e)
{
    using (DropDownList ddlpagesize = (DropDownList)sender)
    {
        gv_transaction.PageSize = int.Parse(ddlpagesize.SelectedValue);
        gv_transaction.PageIndex = 0;
        BindTransactionGrid();
    }
}

现在,当我更改下拉列表值时,SelectedIndex 更改事件不会触发。 但有趣的是,当我从页面大小 Dropdownlist 的启动中删除 using 语句时; Selectedindex 事件正在完美触发。请告诉我与 Gridview 中动态下拉列表的 dropdownlist 和 selectedIndex Changed 事件的处理是否有任何关系

I have a Gridview for which Dropdown list has to be added on the run time at the Pager row. I have added the below code on the Gridview RowCreated.

protected void gv_transaction_RowCreated(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.Pager)
    {
        using (DropDownList ddlpagesize = new DropDownList())
        {
            ddlpagesize.Items.Add("25");
            ddlpagesize.Items.Add("50");
            ddlpagesize.Items.Add("75");
            ddlpagesize.Items.Add("100");
            ddlpagesize.Items.Add("150");
            ddlpagesize.Items.Add("200");
            ddlpagesize.AutoPostBack = true;
            ddlpagesize.Items.FindByText(gv_transaction.PageSize.ToString()).Selected = true;
            ddlpagesize.SelectedIndexChanged += ddlpagesize_SelectedIndexChanged;
            using (Table tbl = (Table)e.Row.Cells[0].Controls[0])
            {
                using (TableCell cell = new TableCell())
                {
                    cell.Controls.Add(new LiteralControl("<b>Page Size: </b>"));
                    cell.Controls.Add(ddlpagesize);
                    tbl.Rows[0].Cells.AddAt(0, cell);
                }
            }
        }
    }
}
protected void ddlpagesize_SelectedIndexChanged(object sender, EventArgs e)
{
    using (DropDownList ddlpagesize = (DropDownList)sender)
    {
        gv_transaction.PageSize = int.Parse(ddlpagesize.SelectedValue);
        gv_transaction.PageIndex = 0;
        BindTransactionGrid();
    }
}

Now, SelectedIndex change event is not firing, when I change the dropdownlist value.
But interestingly, when I remove the using statement from the initiation of page size Dropdownlist; Selectedindex event is firing perfectly. Please tell me if there is any relation with the disposing of dropdownlist and selectedIndex Changed event for the dynamic dropdown in a Gridview

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

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

发布评论

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

评论(1

幻想少年梦 2024-11-22 22:36:58

您不需要将 asp.net 控件包装在 using 语句中,asp.net 会在您的控件上自动调用 dispose,我认为您的 using 语句导致它们过早被处置。

You don't need to wrap asp.net controls in using statements, asp.net will call dispose automatically on your controls, i think your using statements are causing them to be disposed too early.

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