关于gridview的双击调出div层的问题 谁有关于gridview双击调出div层的代码.我主要用途就是在本页调出一个div层并检索一行然后显示到层里,这样进行操作修改...我也有过类似的代码.但只会调用没看懂过.希望有哪位高手,能给我个简便的...谢谢(发我邮箱也行[email protected])急需! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 双击时间触发JS弹出DIV层展示操作 双击时间触发JS弹出DIV层展示操作。。你那个层是用来干什么的? gridview 长文本显示省略号 弹出div层(转) 概述:1.gridview某列文本长度超过某值显示省略号 2.但鼠标移动到该列单元格时弹出div层,显示全部信息其实网上有很类似到资料,不过没有看见完整的,容易用的,所以也小费了点力气!1. gridview某列文本长度超过某值显示省略号 主要说利用服务器端绑定数据时做字符串处理,过长到显示“......”省略号。同时完整信息存放在一个隐藏到div中,为2步做准备。绑定的处理代码(详细看下面到例子) view plaincopy to clipboardprint?<%# Eval("ProductName").ToString().Length > 10 ? Eval("ProductName").ToString().Substring(0,10) + "..." : Eval("ProductName").ToString() %> <%# Eval("ProductName").ToString().Length > 10 ? Eval("ProductName").ToString().Substring(0,10) + "..." : Eval("ProductName").ToString() %> 其中ProductName 是绑定到数据库表到列名。2.鼠标移动到该列单元格时弹出div层,显示全部信息 当鼠标移动到该列到单元格时触发onmouseover事件,获取鼠标的坐标用来初始化div到坐标。用document.createElement()创建div元素,设置div到属性,最主要到是 position:absolute(这里用div分层应该能做不过对这个还不熟悉)。在onmouseout的处理方法中删除该div:view plaincopy to clipboardprint?document.body.removeChild(div_green);//参数是i document.body.removeChild(div_green);//参数是i 3 .下面说完整的例子 数据库用的说nothwind 的表 Order Details Extended view plaincopy to clipboardprint?<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridviewDiv.aspx.cs" Inherits="GridviewDiv" %> <!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> <mce:style type="text/css"><!-- .menuClass { background-color:green; filter:alpha(opacity=50); margin-top:-2; width:98px; position:absolute; } --></mce:style><style type="text/css" mce_bogus="1">.menuClass { background-color:green; filter:alpha(opacity=50); margin-top:-2; width:98px; position:absolute; }</style> <mce:script type="text/javascript" language ="javascript"><!-- function ShowRec() { //取得鼠标坐标 var x,y; if(!document.all) { x=pageX; y=pageY; } else { x=document.body.scrollLeft+event.clientX; //鼠标X轴的值 y=document.body.scrollTop+event.clientY; //鼠标Y轴的值 // alert(x+"--"+y) } //创建div 设定它到属性 var div = document.createElement("div"); div.style.top = y-10; div.style.left = x+10; // div.style.background="green"; div.id="div_green"; div.className = "menuClass";//层样式 document.body.appendChild(div); //获取存放完整信息的div var ele = event.srcElement; var rec = ele.nextSibling; div.innerHTML =rec.innerHTML ; // var ele = event.srcElement; // var rec = ele.nextSibling; // rec.style.display = ''; // if(rec) // { // if(rec.style.display ='none') // { // rec.style.display = ''; // } // else // { // rec.style.display ='none'; // } // } } function DropDiv() { //删除div document.body.removeChild(div_green);//参数是i } // --></mce:script> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="OrderID,ProductID" DataSourceID="SqlDataSource1" Width="399px" AllowPaging="True"> <Columns> <asp:BoundField DataField="OrderID" HeaderText="OrderID" ReadOnly="True" SortExpression="OrderID" /> <asp:BoundField DataField="ProductID" HeaderText="ProductID" ReadOnly="True" SortExpression="ProductID" /> <asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" > </asp:BoundField> <asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" /> <asp:BoundField DataField="Quantity" HeaderText="Quantity" SortExpression="Quantity" /> <asp:BoundField DataField="Discount" HeaderText="Discount" SortExpression="Discount" /> <asp:BoundField DataField="ExtendedPrice" HeaderText="ExtendedPrice" ReadOnly="True" SortExpression="ExtendedPrice" /> <asp:TemplateField HeaderText="标题" SortExpression="ProductName"> <ItemTemplate> <a onmouseout="DropDiv();" onmouseover="ShowRec();" > <%# Eval("ProductName").ToString().Length > 10 ? Eval("ProductName").ToString().Substring(0,10) + "..." : Eval("ProductName").ToString() %> </a> <div id="divRec" style="display:none" mce_style="display:none"> <%# DataBinder.Eval(Container.DataItem, "ProductName")%> </div> </ItemTemplate> <ItemStyle Width="360px" Wrap="False" /> </asp:TemplateField> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT * FROM [Order Details Extended]"></asp:SqlDataSource> </div> </form> </body> </html> GridView的RowDataBound设置每行的ondblclick事件 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes.Add("ondblclick", "test("+e.Row.RowIndex+")"); } }js调用该行数据,仅用alert,楼主可放到div中 <script type="text/javascript"> function test(no) { var gv = document.getElementById("GridView1.ClientID"); var rowStr = ""; var myRow = gv.rows(no+1); for (var j = 0; j < myRow.cells.length; j++) { rowStr += myRow.cells(j).innerText + "/"; } alert(rowStr); } </script> 非常不错!<script type="text/javascript"> function test(no) { var gv = document.getElementById("GridView1.ClientID"); var rowStr = ""; var myRow = gv.rows(no+1); for (var j = 0; j < myRow.cells.length; j++) { rowStr += myRow.cells(j).innerText + "/"; } alert(rowStr); } </script>可以改改直接<script> function test(no){ document.getElement("divid").style.display="block";//显示div }</script>但是重后台穿过来的那个no我想把它赋给<asp:TextBox ID="tname" runat="server">并且textbox在divid这个层里!!!!!! <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="img_Default" %><!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></head><body style="height:100%; width:100%; margin:0px;"> <form id="form1" runat="server"> <div> <center> <asp:GridView ID="GridView1" runat="server" onrowdatabound="GridView1_RowDataBound" Width="479px" onpageindexchanging="GridView1_PageIndexChanging" AutoGenerateColumns="False" onrowupdating="GridView1_RowUpdating"> <Columns> <asp:TemplateField HeaderText="id"> <ItemTemplate> <%#Eval("id") %> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="sex"> <ItemTemplate> <%#Eval("tm") %> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="update"> <ItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" CommandName="update">修改</asp:LinkButton> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <br /><br />数字: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="add" onclick="Button1_Click" /> </center> </div> <div id="tt" style="position:absolute; width:100%; top:0px;height:100%; background-color:gray; display:none;z-index:999px; filter:alpha(opacity=90);"> <center style="margin-top:230px;"> <asp:Panel ID="Panel1" runat="server" BackColor="Black" Width="300px" ForeColor="White"> <table> <tr><td colspan="2" style="text-align:center;">个人信息</td></tr> <tr> <td>id:</td> <td> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td> </tr> <tr> <td>sex:</td> <td> <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox></td> </tr> <tr> <td style="text-align:center;" colspan="2"> <asp:Button ID="Button2" runat="server" Text="upt" /> <asp:Button ID="Button3" runat="server" Text="cancel" OnClientClick="document.getElementById('tt').style.display='none'; return false;" /></td> </tr> </table> </asp:Panel> </center> </div> </form></body></html> protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { string hm = GridView1.DataKeys[e.RowIndex].Values["id"].ToString(); string tm = GridView1.DataKeys[e.RowIndex].Values["tm"].ToString(); TextBox2.Text = hm; TextBox3.Text = tm; Page.ClientScript.RegisterStartupScript(this.GetType(), "er", " document.getElementById('tt').style.display='block';", true); } 唉 贴晚了 刚刚正在和客户交谈其实方法有很多 ajax的控件直接拖着也可以 不过有时候挺喜欢自己写的 像sina,163,qq这样的大公司的主页,怎么做到显示这么快的 asp.net中的这样一个问题,望指教!!!! 急!急!急!把Datagrid的EnableViewState设为False,怎么样做才能不影响翻页功能。 在xml中如何如何添加<?xml version="1.0"...> asp.net中调用dll的问题,帮忙看下。 菜鸟一只 求指错 asp.net 控件位置怎么设置? 如何做模糊查询? 哪里有 VS.NET 中文正式版下载,谢谢! 当我点击一个Button时 怎么跟dataGrideView里的数据联系起来 层级权限问题 asp.net 程序IIS自动部署问题
你那个层是用来干什么的?
概述:1.gridview某列文本长度超过某值显示省略号 2.但鼠标移动到该列单元格时弹出div层,显示全部信息其实网上有很类似到资料,不过没有看见完整的,容易用的,所以也小费了点力气!1. gridview某列文本长度超过某值显示省略号 主要说利用服务器端绑定数据时做字符串处理,过长到显示“......”省略号。同时完整信息存放在一个隐藏到div中,为2步做准备。绑定的处理代码(详细看下面到例子) view plaincopy to clipboardprint?
<%# Eval("ProductName").ToString().Length > 10 ? Eval("ProductName").ToString().Substring(0,10) + "..." : Eval("ProductName").ToString() %>
<%# Eval("ProductName").ToString().Length > 10 ? Eval("ProductName").ToString().Substring(0,10) + "..." : Eval("ProductName").ToString() %> 其中ProductName 是绑定到数据库表到列名。2.鼠标移动到该列单元格时弹出div层,显示全部信息 当鼠标移动到该列到单元格时触发onmouseover事件,获取鼠标的坐标用来初始化div到坐标。用document.createElement()创建div元素,设置div到属性,最主要到是 position:absolute(这里用div分层应该能做不过对这个还不熟悉)。在onmouseout的处理方法中删除该div:view plaincopy to clipboardprint?
document.body.removeChild(div_green);//参数是i
document.body.removeChild(div_green);//参数是i 3 .下面说完整的例子 数据库用的说nothwind 的表 Order Details Extended view plaincopy to clipboardprint?
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridviewDiv.aspx.cs" Inherits="GridviewDiv" %>
<!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>
<mce:style type="text/css"><!--
.menuClass
{
background-color:green;
filter:alpha(opacity=50);
margin-top:-2;
width:98px;
position:absolute;
}
--></mce:style><style type="text/css" mce_bogus="1">.menuClass
{
background-color:green;
filter:alpha(opacity=50);
margin-top:-2;
width:98px;
position:absolute;
}</style>
<mce:script type="text/javascript" language ="javascript"><!--
function ShowRec()
{
//取得鼠标坐标
var x,y;
if(!document.all)
{
x=pageX;
y=pageY;
}
else
{
x=document.body.scrollLeft+event.clientX; //鼠标X轴的值
y=document.body.scrollTop+event.clientY; //鼠标Y轴的值
// alert(x+"--"+y)
}
//创建div 设定它到属性
var div = document.createElement("div");
div.style.top = y-10;
div.style.left = x+10;
// div.style.background="green";
div.id="div_green";
div.className = "menuClass";//层样式
document.body.appendChild(div);
//获取存放完整信息的div
var ele = event.srcElement;
var rec = ele.nextSibling;
div.innerHTML =rec.innerHTML ;
// var ele = event.srcElement;
// var rec = ele.nextSibling;
// rec.style.display = '';
// if(rec)
// {
// if(rec.style.display ='none')
// {
// rec.style.display = '';
// }
// else
// {
// rec.style.display ='none';
// }
// }
}
function DropDiv()
{
//删除div
document.body.removeChild(div_green);//参数是i
}
// --></mce:script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="OrderID,ProductID"
DataSourceID="SqlDataSource1" Width="399px" AllowPaging="True">
<Columns>
<asp:BoundField DataField="OrderID" HeaderText="OrderID" ReadOnly="True" SortExpression="OrderID" />
<asp:BoundField DataField="ProductID" HeaderText="ProductID" ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" >
</asp:BoundField>
<asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" />
<asp:BoundField DataField="Quantity" HeaderText="Quantity" SortExpression="Quantity" />
<asp:BoundField DataField="Discount" HeaderText="Discount" SortExpression="Discount" />
<asp:BoundField DataField="ExtendedPrice" HeaderText="ExtendedPrice" ReadOnly="True"
SortExpression="ExtendedPrice" />
<asp:TemplateField HeaderText="标题" SortExpression="ProductName">
<ItemTemplate>
<a onmouseout="DropDiv();" onmouseover="ShowRec();" > <%# Eval("ProductName").ToString().Length > 10 ? Eval("ProductName").ToString().Substring(0,10) + "..." : Eval("ProductName").ToString() %> </a>
<div id="divRec" style="display:none" mce_style="display:none"> <%# DataBinder.Eval(Container.DataItem, "ProductName")%> </div>
</ItemTemplate>
<ItemStyle Width="360px" Wrap="False" />
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT * FROM [Order Details Extended]"></asp:SqlDataSource>
</div>
</form>
</body>
</html>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("ondblclick", "test("+e.Row.RowIndex+")");
}
}
js调用该行数据,仅用alert,楼主可放到div中
<script type="text/javascript">
function test(no) {
var gv = document.getElementById("GridView1.ClientID");
var rowStr = "";
var myRow = gv.rows(no+1);
for (var j = 0; j < myRow.cells.length; j++) {
rowStr += myRow.cells(j).innerText + "/";
}
alert(rowStr);
}
</script>
非常不错!
<script type="text/javascript">
function test(no) {
var gv = document.getElementById("GridView1.ClientID");
var rowStr = "";
var myRow = gv.rows(no+1);
for (var j = 0; j < myRow.cells.length; j++) {
rowStr += myRow.cells(j).innerText + "/";
}
alert(rowStr);
}
</script>可以改改直接<script>
function test(no){
document.getElement("divid").style.display="block";//显示div
}
</script>
但是重后台穿过来的那个no我想把它赋给
<asp:TextBox ID="tname" runat="server">并且textbox在divid这个层里!!!!!!
<head runat="server">
<title>无标题页</title>
</head>
<body style="height:100%; width:100%; margin:0px;">
<form id="form1" runat="server">
<div>
<center>
<asp:GridView ID="GridView1" runat="server"
onrowdatabound="GridView1_RowDataBound" Width="479px"
onpageindexchanging="GridView1_PageIndexChanging"
AutoGenerateColumns="False" onrowupdating="GridView1_RowUpdating">
<Columns>
<asp:TemplateField HeaderText="id">
<ItemTemplate>
<%#Eval("id") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="sex">
<ItemTemplate>
<%#Eval("tm") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="update">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="update">修改</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br /><br />数字:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="add" onclick="Button1_Click" />
</center>
</div>
<div id="tt" style="position:absolute; width:100%; top:0px;height:100%; background-color:gray; display:none;z-index:999px; filter:alpha(opacity=90);">
<center style="margin-top:230px;">
<asp:Panel ID="Panel1" runat="server" BackColor="Black" Width="300px" ForeColor="White">
<table>
<tr><td colspan="2" style="text-align:center;">个人信息</td></tr>
<tr>
<td>id:</td>
<td>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>sex:</td>
<td>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td style="text-align:center;" colspan="2">
<asp:Button ID="Button2" runat="server" Text="upt" />
<asp:Button ID="Button3" runat="server" Text="cancel" OnClientClick="document.getElementById('tt').style.display='none'; return false;" /></td>
</tr>
</table>
</asp:Panel>
</center>
</div>
</form>
</body>
</html>
{
string hm = GridView1.DataKeys[e.RowIndex].Values["id"].ToString();
string tm = GridView1.DataKeys[e.RowIndex].Values["tm"].ToString();
TextBox2.Text = hm; TextBox3.Text = tm;
Page.ClientScript.RegisterStartupScript(this.GetType(), "er", " document.getElementById('tt').style.display='block';", true);
}