如何点击gridview获取当前行id到ViewState中不用按钮

解决方案 »

  1.   

    到viewState 就得回传
    回传一般都用按钮事件是不是这样也可以GridView 添加客户端点击事件
    事件处理函数中
    用ajax的方法
    把选中的行的id 
    传到一个页面
    此页面把ID放到Session中
      

  2.   

    如何点击gridview获取当前行的id
      

  3.   

    用client-callbackpublic partial class _Default : System.Web.UI.Page, ICallbackEventHandler
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "scriptKey", "function setViewState(value, context)  {" + Page.ClientScript.GetCallbackEventReference(this, "value", "OnSuccess", "context") + "}", true);
        }
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes["onclick"] = "setViewState(" + GridView1.DataKeys[e.Row.RowIndex].Value + ", null)";
            }
        }    #region ICallbackEventHandler 成员    public string GetCallbackResult()
        {
            return ViewState["PK"].ToString();
        }    public void RaiseCallbackEvent(string eventArgument)
        {
            ViewState["PK"] = eventArgument;
        }    #endregion
       
    }.aspx
    <head runat="server">
        <title>无标题页</title>
        <script type="text/javascript">
            function OnSuccess(result)
            {
                document.getElementById("funny").innerText = result;
            }
        </script>
    </head>
    ...
    <div id="funny"></div>
      

  4.   

    Protected Sub GridView2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView2.SelectedIndexChanged 
                  ViewState("PageIndex")= GridView2.DataKeys(GridView2.SelectedIndex).Value 
            Bindclass() 
        End Sub