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 に答える