使用C#的Asp.Net,单击Datagrid行时打开Web表单

时间:2010-09-17 04:39:47

标签: javascript asp.net datagrid onclick row

使用Datagrid我在点击数据网格行上尝试Web表单,任何正文建议我如何执行此操作。

1 个答案:

答案 0 :(得分:0)

为行添加javascript click-eventhandler

背后的代码

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if(e.Row.RowType == DataControlRowType.DataRow )
    {            
        User selUser = e.Row.DataItem as User;
        e.Row.Attributes.Add("onclick","openWindow('" + selUser.Id + "')");
    }
}

Javascript功能

<script language="javascript">


        function openWindow( userId )
        {
            var url= "http://www.google.com";
            newwindow=window.open(url,'name','height=400,width=200');
        if (window.focus) {newwindow.focus()}
        }


    </script>