现在遇到一个问题 选中GridView的一行,我是这样做的: protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onClick", "javascript:__doPostBack('" + GridView1.ID + "','Select$" +  e.Row.RowIndex + "');");
        }
    }然后设置GridView允许选择,可是每次选择一行的时候总是触发回传,我不想让他回传,然后仍能获取这一行的DataKey,该怎么做呢?

解决方案 »

  1.   

     e.Row.Attributes.Add("onclick", "A('Hf_Id','" + this.gv.DataKeys[e.Row.RowIndex].Value+ "')");
    function A(a,b)
    {
    alert(b);
    document.getElementById(a).value=b;
    }
      

  2.   

    首先纠正你两点:1.确保有下面的js脚本和input隐藏域
    <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
    <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
    <script type="text/javascript">
    //<![CDATA[
    var theForm = document.forms['form1'];
    if (!theForm) {
        theForm = document.form1;
    }
    function __doPostBack(eventTarget, eventArgument) {
        if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
            theForm.__EVENTTARGET.value = eventTarget;
            theForm.__EVENTARGUMENT.value = eventArgument;
            theForm.submit();
        }
    }
    //]]>
    </script>2.e.Row.Attributes.Add("onClick", "javascript:__doPostBack('" + GridView1.ClientID + "','Select$" + e.Row.RowIndex + "');");
      

  3.   

    两个回答:1. asp.net代码中你从来不需要写 __doPostback。在asp.net中,脚本是使用 GetPostBackEventReference 来生成的。2. 你可以考虑放弃 asp.net 编程,肯定也不适合使用 jsp 或者 php。只能适合使用 html+javascript编程啊。