如何在编辑模式下在 GridView 中 FindControl() ?

发布于 2024-09-07 03:02:56 字数 270 浏览 2 评论 0原文

我想访问控件并用它们的值更新数据库。请注意使用以下代码:

void grdList_UpdateCommand(object source, GridCommandEventArgs e)
{
        string str = ((RadTextBox)e.Item.FindControl("txtLookupItemValue")).Text;
}

我有权控制 txtLookupItemValue,但它包含编辑前的内容,而不是用户输入的实际值。

I want to access controls and update database with their value. Notice using following code:

void grdList_UpdateCommand(object source, GridCommandEventArgs e)
{
        string str = ((RadTextBox)e.Item.FindControl("txtLookupItemValue")).Text;
}

I have access to control txtLookupItemValue, but it contains before-edit content, not actual value that user has entered.

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

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

发布评论

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

评论(2

北方。的韩爷 2024-09-14 03:02:56

您是否尝试在编辑事件期间设置字符串:

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{

   string str = ((RadTextBox)e.Item.FindControl("txtLookupItemValue")).Text;

}

然后更新数据库并重新绑定网格视图以显示更新的行。

have you tried setting the string during the edit event:

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{

   string str = ((RadTextBox)e.Item.FindControl("txtLookupItemValue")).Text;

}

Then update your DB and rebind the gridview to display the updated row.

热鲨 2024-09-14 03:02:56

我认为你可以在网格更新时获取该值。例如:

protected void GridUpdating(object sender, GridViewUpdateEventArgs e)
{
string str = (RadTextBox)this.yourGridviewName.Rows[e.RowIndex].FindControl("txtLookupItemValue").Text;
}

然后将其添加到 aspx 上的 gridview 中:

OnRowUpdating="GridUpdating"

I think you can get the value when the grid is updating. E.g:

protected void GridUpdating(object sender, GridViewUpdateEventArgs e)
{
string str = (RadTextBox)this.yourGridviewName.Rows[e.RowIndex].FindControl("txtLookupItemValue").Text;
}

Then add this to the gridview on the aspx:

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