0

嗨,我想从网格视图中提取索引(行),我在其中使用了一个文本框。id 应该从 gridview 中的文本框中提取。我使用这段代码:

protected void TextBox_Email_TextChanged(object sender, EventArgs e)

{
    TextBox thisTextBox = (TextBox)sender;
    GridViewRow currentRow = (GridViewRow)thisTextBox.Parent.Parent;
    int rowindex = 0;
    int idx = currentRow.RowIndex;

    string ArticleID = (string)GridView1.DataKeys[idx].Values[1];
}

但是VS给了我这个错误:

Unable to cast object of type 'System.Web.UI.WebControls.DataControlFieldCell' to type 'System.Web.UI.WebControls.GridViewRow'.

任何身体都可以帮助我吗?

谢谢

4

1 回答 1

3

的父级DataControlFieldCell将是GridViewRow

protected void TextBox_Email_TextChanged(object sender, EventArgs e)
{
    TextBox thisTextBox = (TextBox)sender;
    GridViewRow currentRow = (GridViewRow)thisTextBox.Parent.Parent.Parent;
    int rowindex = 0;
    int idx = currentRow.RowIndex;

    string ArticleID = (string)GridView1.DataKeys[idx].Values[1];
}
于 2013-06-08T14:36:42.093 回答