2

私はGridviewを持っており、rowDataboundでその行をクリックして作成し、モーダルポップアップを表示しています。行がクリックされたときに、その行のIDが渡される必要があります。

protected void grdOrderProduct_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#ceedfc'");
        e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=''");
        e.Row.Attributes.Add("style", "cursor:pointer;");
        e.Row.Attributes["onClick"] = Page.ClientScript.GetPostBackClientHyperlink(btnPop, "12");
    }
}

サーバーコントロールでこの「12」を取得するにはどうすればよいですか。私はデモ用に静的なものとして12を入れました。しかし、それは変わるでしょう。

4

2 に答える 2

2

あなたもこのようにすることができます

e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink
(this.GridView1, "Select$" + e.Row.RowIndex);
于 2012-11-09T12:01:57.373 に答える
0

クリックされた行を知るには、のRowプロパティを使用する必要がありますGridViewRowEventArgs

    protected void grdOrderProduct_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#ceedfc'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=''");
            e.Row.Attributes.Add("style", "cursor:pointer;");
            e.Row.Attributes["onClick"] = Page.ClientScript.GetPostBackClientHyperlink(btnPop, e.Row.RowIndex.ToString());

        }
    }

RowIndexは引数としてに渡されますbtnPop。受信するにbtnPopは、を実装する必要がありますIPostBackEventHandler

このような:

public class MyControl : Button, IPostBackEventHandler
  {

    // Use the constructor to defined default label text.
    public MyControl()
    {
    }

    // Implement the RaisePostBackEvent method from the
    // IPostBackEventHandler interface. 
    public void RaisePostBackEvent(string eventArgument)
    {
      //You receive the row number here.
    }
  }

ClientScriptManager.GetPostBackClientHyperlinkを参照してください

于 2012-08-30T09:02:25.267 に答える