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");
You need to use the GridViewUpdateEventArgs e
as it contains index of row being updated.
Use something like
uxManageSponsoredContentsDisplayer.Rows[e.RowIndex].FindControl("uxEffectiveStartDateInput")
精彩评论