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

you also can do like this

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 回答