C# code
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onclick", "window.open('newpage.aspx')");
            }        }
如何把这个代码修改成像hyperlink中newpage.aspx?id={0}那样,一点能直接传值到'newpage.aspx'.请大家给指点下啊~谢谢~1

解决方案 »

  1.   

    gridview中添加超链接列
    <Columns>
    <asp:HyperLinkField DataNavigateUrlFields="id" DataNavigateUrlFormatString="newpage.aspx?id={0}" DataTextField="title" HeaderText="主题" />
    </Columns>
      

  2.   

    点“行”跳转?也只能用javascript了
      

  3.   


            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("style", "cursor:hand;");            if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    string strID = GridView1.DataKeys[e.Row.RowIndex].Value.ToString();
                    e.Row.Attributes.Add("onclick", "userSelected('" + strID + "'," + (e.Row.RowIndex + 1) + ",this.style.backgroundColor);this.style.backgroundColor='#99cc00'; this.style.color='buttontext';this.style.cursor='default';");
                }
            }我这个是鼠标移到上面改变颜色的功能
    你改下就可以了
      

  4.   

      e.Row.Attributes.Add("onclick", "window.open('newpage.aspx?id'"+e.Row.cells[1].Text.ToString().Trim()+")"); 
      

  5.   

     e.Row.Attributes.Add("onclick", "window.open('newpage.aspx?id="+this.GridView1.DataKeys[e.Row.RowIndex].Value+"')"); 
      

  6.   


    能不新打开窗口,而直接就跳转吗?谢谢~1不用window.open。
      

  7.   

    e.Row.Attributes.Add("onclick", "window.location.href='newpage.aspx?id="+this.GridView1.DataKeys[e.Row.RowIndex].Value+"';");