1

私はこのようなことを試しましたが、うまくいきませんでした:

GridViewRow row = (GridViewRow)(((Repeater)e.CommandSource).NamingContainer); 
Repeater _rpt1 = row.Cells[8].FindControl("rptReg") as Repeater;

エラー:

Unable to cast object of type 'System.Web.UI.WebControls.Button' to type 'System.Web.UI.WebControls.Repeater'.

OnRowCommandGridView を使用してイベントで以下のコードを使用する方法はありますか?

実際には、gridview コントロールから行を削除しようとしています。ユーザーがそれをクリックすると、複数の ID を取得して SP に渡し、テーブルを更新します。databind the gridview

GridViewRow row = gv.SelectedRow;           
    Repeater _rpt = gv.Rows[e.RowIndex].Cells[8].FindControl("rptReg") as Repeater;
    Repeater _rpt1 = gv.Rows[e.RowIndex].Cells[9].FindControl("rptVisitor") as Repeater;

    foreach (RepeaterItem item in _rpt.Items)
    {
        TextBox _txt = item.FindControl("txtId") as TextBox;
        TextBox _txt1 = item.FindControl("txtName") as TextBox;
        //update db
    }
4

2 に答える 2

3

これを試してください:

var viewRow = (GridViewRow)(((ImageButton)e.CommandSource).NamingContainer);
foreach (GridViewRow gvr in gvDetails.Rows)
{
    var btnSelect = (ImageButton)viewRow.FindControl("btnSelect");
    if (gvr == viewRow)
    {
        if (btnSelect.ImageUrl.ToLower() == "~/images/rbnormal.jpg")
        {
            btnSelect.ImageUrl = "~/Images/rbSelected.jpg";
            btnSelect.Enabled = false;
        }
    }
    else
    {
        btnSelect.ImageUrl = "~/Images/rbnormal.jpg";
        btnSelect.Enabled = true;
    }
}
于 2012-10-29T15:26:41.047 に答える
0

エラーは、「rptReg」という名前のコントロールがボタンであることを示しています。

GridView には、複数の ID を保持できる DataKeys というプロパティがあるため、次のように "PersonId" を引き出します。

     string personId = GridView1.DataKeys[e.RowIndex]["PersonId"].ToString();
于 2011-01-31T22:58:35.763 に答える