为GridView每个单元格鼠标移上去显示div
2008-01-17 09:29
302 查看
我这里读的是xml,大家可以参照自己的读取方式将数据转换成表格.
gridview 的RowBound事件里面的内容
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//鼠标经过时候显示div
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
function showdivByCs(table) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// table=table.replace("&","&");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// table=table.replace(">",">");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// table=table.replace("<","<");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// table=table.replace(""",""");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// table=table.replace("'","'");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var x = window.event.x;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var y = window.event.y;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var show = document.getElementById("ShowInfo");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
show.style.visibility = "visible";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
show.style.top = y;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
show.style.left = x;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
show.style.background="#ffff00";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//读取xml
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
document.getElementById("sp").innerHTML=table;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//div跟随鼠标
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
document.onmousemove = moveToMouseLoc;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//鼠标移动时候div跟随
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
function moveToMouseLoc(e)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
x = window.event.x;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
y = window.event.y;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var show = document.getElementById("ShowInfo");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
show.style.left = x;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
show.style.top = y;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return true;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
javascript 里的内容
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (e.Row.RowType == DataControlRowType.DataRow)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// DataSet ds = new DataSet();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for (int i = 0; i < e.Row.Cells.Count; i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string table = "<table cellspacing='0' rules='all' bordercolorlight='#b4b1b1' bordercolordark='#ffffff' border='1'><tr class='title'><td>数据来源</td><td>" + GridView1.Columns[i].HeaderText.ToString() + "</td></tr>";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
XmlDocument xmlDoc = new XmlDocument();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
xmlDoc.LoadXml(LbHiddenGrid.Text);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//xmlDoc.SelectSingleNode("/Datas/notes[@id='" + i + "']/Source[@Desc='成考']/Data/Year");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//xmlDoc.SelectSingleNode("/Datas/notes[@id='" + i + "']/Source[@Desc='成考']/Data/Year").FirstChild.Value
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
foreach (XmlNode childnode in xmlDoc.SelectSingleNode("/Datas/notes[@id='" + e.Row.RowIndex.ToString() + "']"))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//XmlNode childnode = xmlDoc.SelectSingleNode("/Datas/notes[@id='" + e.Row.RowIndex.ToString() + "']");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//for (int j = 0; j < xmlDoc.SelectSingleNode("/Datas/notes[@id='" + e.Row.RowIndex.ToString() + "']").ChildNodes.Count; j++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
table += "<tr><td>";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string name = childnode.Attributes.GetNamedItem("Desc").InnerText;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
table += name + "</td><td>";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string value = childnode.SelectSingleNode("Data/" + ((BoundField)(GridView1.Columns[i])).DataField).InnerText;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
table += value + "</td></tr>";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//childnode.SelectSingleNode("/Data/" );
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//ds.ReadXml(XmlReader.Create(new System.IO.StringReader(childnode.FirstChild.OuterXml)));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
table += "</table>";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//string ss = Server.HtmlEncode(table);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
e.Row.Cells[i].Attributes.Add("onmouseover", "showdivByCs("" + table + "")");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
e.Row.Cells[i].Attributes.Add("onmouseout", "Remove()");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
gridview 的RowBound事件里面的内容
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//鼠标经过时候显示div
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
function showdivByCs(table) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// table=table.replace("&","&");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// table=table.replace(">",">");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// table=table.replace("<","<");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// table=table.replace(""",""");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// table=table.replace("'","'");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var x = window.event.x;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var y = window.event.y;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var show = document.getElementById("ShowInfo");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
show.style.visibility = "visible";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
show.style.top = y;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
show.style.left = x;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
show.style.background="#ffff00";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//读取xml
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
document.getElementById("sp").innerHTML=table;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//div跟随鼠标
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
document.onmousemove = moveToMouseLoc;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//鼠标移动时候div跟随
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
function moveToMouseLoc(e)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
x = window.event.x;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
y = window.event.y;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var show = document.getElementById("ShowInfo");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
show.style.left = x;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
show.style.top = y;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return true;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
javascript 里的内容
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (e.Row.RowType == DataControlRowType.DataRow)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// DataSet ds = new DataSet();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for (int i = 0; i < e.Row.Cells.Count; i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string table = "<table cellspacing='0' rules='all' bordercolorlight='#b4b1b1' bordercolordark='#ffffff' border='1'><tr class='title'><td>数据来源</td><td>" + GridView1.Columns[i].HeaderText.ToString() + "</td></tr>";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
XmlDocument xmlDoc = new XmlDocument();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
xmlDoc.LoadXml(LbHiddenGrid.Text);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//xmlDoc.SelectSingleNode("/Datas/notes[@id='" + i + "']/Source[@Desc='成考']/Data/Year");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//xmlDoc.SelectSingleNode("/Datas/notes[@id='" + i + "']/Source[@Desc='成考']/Data/Year").FirstChild.Value
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
foreach (XmlNode childnode in xmlDoc.SelectSingleNode("/Datas/notes[@id='" + e.Row.RowIndex.ToString() + "']"))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//XmlNode childnode = xmlDoc.SelectSingleNode("/Datas/notes[@id='" + e.Row.RowIndex.ToString() + "']");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//for (int j = 0; j < xmlDoc.SelectSingleNode("/Datas/notes[@id='" + e.Row.RowIndex.ToString() + "']").ChildNodes.Count; j++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
table += "<tr><td>";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string name = childnode.Attributes.GetNamedItem("Desc").InnerText;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
table += name + "</td><td>";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string value = childnode.SelectSingleNode("Data/" + ((BoundField)(GridView1.Columns[i])).DataField).InnerText;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
table += value + "</td></tr>";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//childnode.SelectSingleNode("/Data/" );
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//ds.ReadXml(XmlReader.Create(new System.IO.StringReader(childnode.FirstChild.OuterXml)));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
table += "</table>";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//string ss = Server.HtmlEncode(table);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
e.Row.Cells[i].Attributes.Add("onmouseover", "showdivByCs("" + table + "")");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
e.Row.Cells[i].Attributes.Add("onmouseout", "Remove()");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
相关文章推荐
- 为GridView每个单元格鼠标移上去显示div
- 为GridView每个单元格鼠标移上去显示div
- 怎么设置GridView的单元格在内容显示超过长度的时候用省略号代替而不是换行当鼠标移上去的时候将影藏的内容提示出来
- GridView中的每个单元格文本长度的控制,鼠标悬停时,显示单元格所有的内容
- GridView 中设置某列,截取字符串加"..." 和 鼠标放上去字符全部显示 .
- jquery鼠标放上去显示悬浮层即弹出定位的div层
- 截取单元格内超长的字符串并用当鼠标指上去时显示全部字符串
- 超过单元格长度的文本用省略号表示,利用title属性实现鼠标移上去会显示全文,但有时候只看到一部分
- 鼠标指向GridView某列显示DIV浮动列表
- 鼠标放上去,div高度随文字增加,并显示剩余的文字。
- 现在我用gridview绑定到数据库,但是有一列很长,有没有办法实现当绑定的时候显示前面几个字,当鼠标放上去的时候显示全部内容,郁闷阿
- 一个令人纠结的弹窗问题,鼠标放上去显示div,鼠标离开div消失
- GridView 中设置某列,截取字符串加"..." 和 鼠标放上去字符全部显示
- 鼠标移上去出现显示层,并且出现在同一个div中
- GridView鼠标移上某行显示浮动DIV提示信息
- gridview列显示,截取其中前面的几个字显示出来,当鼠标放上去的时候显示全部
- gridview列显示,截取其中前面的几个字显示出来,当鼠标放上去的时候显示全部——使用LinkButton的方法
- div不显示滚动条但实现鼠标移上去可以上下滚动的效果
- asp.net后台对sql语句排序,筛选,gridview隐藏过长的字符串鼠标放上去显示全部,dropdownlist在前台显示拼接字符串
- gridview列显示,截取其中前面的几个字显示出来,当鼠标放上去的时候显示全部