1

BoundFieldカスタムのカスタム(列) を作成しようとしていますGridViewFooterRow列のフィルタリングを管理するために、にテキスト ボックスを追加しました。うまく表示されますが、TextChangedイベントが発生することはありません。ポストバックごとにテキストボックスが再作成され、永続化されていないためだと思います。

これが私のコードです:

public class Column : BoundField
{
    public override void InitializeCell(DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
    {
        base.InitializeCell(cell, cellType, rowState, rowIndex);
        if (cellType == DataControlCellType.Footer)
        {
            TextBox txtFilter = new TextBox();
            txtFilter.ID = Guid.NewGuid().ToString();
            txtFilter.Text = "";
            txtFilter.AutoPostBack = true;
            txtFilter.TextChanged += new EventHandler(txtFilter_TextChanged);
            cell.Controls.Add(txtFilter);
        }
    }

    protected void txtFilter_TextChanged(object sender, EventArgs e)
    {
        // Never get here
    }
}

チェックボックスで試してみましたが、うまくいきました。

4

2 に答える 2

0

解決:

ようやく問題が見つかりましたが、理解できません! 問題は、Guid で生成された ID プロパティでした。それを削除するだけで私の問題は解決しました。

public class Column : BoundField
{
    public override void InitializeCell(DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
    {
        base.InitializeCell(cell, cellType, rowState, rowIndex);
        if (cellType == DataControlCellType.Footer)
        {
            TextBox txtFilter = new TextBox();
            // Removing this worked
            //txtFilter.ID = Guid.NewGuid().ToString(); 
            txtFilter.Text = "";
            txtFilter.AutoPostBack = true;
            txtFilter.TextChanged += new EventHandler(txtFilter_TextChanged);
            cell.Controls.Add(txtFilter);
        }
    }

    protected void txtFilter_TextChanged(object sender, EventArgs e)
    {
        // Never get here
    }
}
于 2013-04-18T13:15:52.217 に答える