GibboK
GibboK

Reputation: 73908

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

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");

Upvotes: 1

Views: 278

Answers (1)

Axarydax
Axarydax

Reputation: 16603

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

Use something like

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

Upvotes: 2

Related Questions