gpt4 book ai didi

c# - ASP.NET Gridview 在绑定(bind)之前将值附加到编辑模板控件

转载 作者:行者123 更新时间:2023-11-30 18:40:49 25 4
gpt4 key购买 nike

我有一个支持更新记录的 GridView 。我有一个带有替换文本框的 Dropdownlist(ddl) 的编辑模板。DDL 绑定(bind)到数据源,我需要附加一个值(该字段的当前值到 DDL)。这使用户能够从 DDL 中选择当前值和备用值。

问题是我需要绑定(bind) DDl ('<%# Bind("Element") %>') 所以更新函数有效但我需要在附加字段的当前值后绑定(bind)它到现在在 RowDataBound 事件期间发生的 DDL。

简而言之;我需要在绑定(bind)之前获取附加到 DDL 的字段的当前值,以便我的更新工作(否则我得到 DDL 不包含 vale 错误)。我可以在 gridview 中检索字段值(单击编辑按钮后)的最早点/事件是什么,以便我可以在绑定(bind)发生之前进行一些管道操作?

帮忙吗?

最佳答案

有趣的问题!你可以处理 RowEditing事件,当行进入“编辑模式”时被触发(当编辑按钮被点击时)。然后只需使用 NewEditIndex属性找到您要编辑的行。

因此,在您的代码隐藏中有这样的内容:

protected void myGridView_RowEditing(object sender, GridViewEditEventArgs e)
{
// the row you're editing
int rowToEdit = e.NewEditIndex;

// The numeric ordinal of your column where your DropDownList is. I just picked 5 at random
int ddlColumnIndex = 5;

// Get the DropDownList you're interested in modifying
DropDownList myDDL = (DropDownList)myGridView.Rows[rowToEdit].Cells[ddlColumnIndex].FindControl("myDDL");

// Do whatever processing you need to do here
}

关于c# - ASP.NET Gridview 在绑定(bind)之前将值附加到编辑模板控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7690100/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com