开发者

How to retrive a Control in a specific ROW in edit mode in a GridView

开发者 https://www.devze.com 2023-02-13 22:18 出处:网络
I have a GridView with many rows. When a User click the EDIT button in开发者_运维知识库 GridView I need to retrieve a Control in that specific row (now in edit mode).

I have a GridView with many rows.

When a User click the EDIT button in开发者_运维知识库 GridView I need to retrieve a Control in that specific row (now in edit mode). This Logic should work on GridEvent _RowUpdating

At the moment my code (wrong) look inside every Row, so the Control founded is not unique and I receive an error.

// Event handler
    protected void uxManageSponsoredContentsDisplayer_RowUpdating(object sender, GridViewUpdateEventArgs e)

// My code (Wrong!!!!):
foreach (GridViewRow row in uxManageSponsoredContentsDisplayer.Rows)
    {
    TextBox uxStartDate = (TextBox)row.FindControl("uxEffectiveStartDateInput");
    }

Hope my question is clear. Any idea how to do it? Thanks


Solution:

    TextBox uxStartDate = (TextBox)uxManageSponsoredContentsDisplayer.Rows[e.RowIndex].FindControl("uxEffectiveStartDateInput");


You need to use the GridViewUpdateEventArgs e as it contains index of row being updated.

Use something like

uxManageSponsoredContentsDisplayer.Rows[e.RowIndex].FindControl("uxEffectiveStartDateInput")
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号