日期:2014-05-18  浏览次数:20441 次

求如何把Js代码添加到GridView的绑定列中,在线。对了立即给分。
<script   LANGUAGE= "Javascript ">  
<!--  
function   openwin(var   id)  
{  
window.open( "info.aspx?id= "+id,   "newwindow ",   "height=100,   width=400,   toolbar=no   ,   menubar=no,   scrollbars=no,   resizable=no,   location=no,   status=no ")  
//写成一行
}  
//-->  
</script>

我想把在gridview的绑定列中加openwin( '+ <%#   Eval(id)%> + ');
为什么不如使呢,请高手给写一下。

对了,立即给分。

------解决方案--------------------
<font onclick= 'showinfo( " <%# DataBinder.Eval(Container.DataItem, "planID ") %> ") ' style= "cursor:hand; "> 详细信息 </font>
------解决方案--------------------
function addRoleRow(rowdata) //rowdata是要插入的那行数据
{
var testTbl=document.getElementById( 'dl_RoleList '); //dl_RoleList是datagrid的名字
var newTr = testTbl.insertRow();
var newTd0 = newTr.insertCell();
newTd0.style.cursor= "hand ";
newTd0.innerText=rowdata.RoleName;//字段名
}
------解决方案--------------------
请参考
//Demo.aspx
<%@ Page Language= "C# " AutoEventWireup= "true " CodeBehind= "Demo.aspx.cs " Inherits= "GridViewDemo " %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<html xmlns= "http://www.w3.org/1999/xhtml " >
<head runat= "server ">
<title> 无标题页 </title>
<script LANGUAGE= "Javascript ">
<!--
function openwin(id)
{
window.open( "info.aspx?id= "+id, "newwindow ", "height=100, width=400, toolbar=no , menubar=no, scrollbars=no, resizable=no, location=no, status=no ");
}
//-->
</script>
</head>
<body>
<form id= "form1 " runat= "server ">
<div>
<asp:SqlDataSource ID= "SqlDataSource1 " runat= "server " ConnectionString= " <%$ ConnectionStrings:NorthwindConnectionString %> "
SelectCommand= "SELECT top 5 [CustomerID], [CompanyName] FROM [Customers] " > </asp:SqlDataSource>

<asp:GridView ID= "GridView1 " runat= "server " DataKeyNames= "CustomerID " AutoGenerateColumns= "False " DataSourceID= "SqlDataSource1 " OnRowDataBound= "GridView1_RowDataBound " >
<Columns>
<asp:BoundField DataField= "CustomerID " HeaderText= "CustomerID " ReadOnly= "True " SortExpression= "CustomerID " FooterText= "XXX " />
<asp:BoundField DataField= "CompanyName " HeaderText= "CompanyName " SortExpression= "CompanyName " FooterText= "XXX " />
</Columns>

</asp:GridView>
</div>
</form>
</body>
</html>

//Demo.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebP