為GridView每個儲存格滑鼠移上去顯示div

來源:互聯網
上載者:User

gridview 的RowBound事件裡面的內容

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    ...{
        if (e.Row.RowType == DataControlRowType.DataRow)
        ...{
            // DataSet ds = new DataSet();

            for (int i = 0; i < e.Row.Cells.Count; i++)
            ...{

                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>";
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(LbHiddenGrid.Text);
                //xmlDoc.SelectSingleNode("/Datas/notes[@id='" + i + "']/Source[@Desc='成考']/Data/Year");
                //xmlDoc.SelectSingleNode("/Datas/notes[@id='" + i + "']/Source[@Desc='成考']/Data/Year").FirstChild.Value
                foreach (XmlNode childnode in xmlDoc.SelectSingleNode("/Datas/notes[@id='" + e.Row.RowIndex.ToString() + "']"))
                ...{
                    //XmlNode childnode = xmlDoc.SelectSingleNode("/Datas/notes[@id='" + e.Row.RowIndex.ToString() + "']");
                    //for (int j = 0; j < xmlDoc.SelectSingleNode("/Datas/notes[@id='" + e.Row.RowIndex.ToString() + "']").ChildNodes.Count; j++)
                    //{

                    table += "<tr><td>";
                    string name = childnode.Attributes.GetNamedItem("Desc").InnerText;
                    table += name + "</td><td>";
                    string value = childnode.SelectSingleNode("Data/" + ((BoundField)(GridView1.Columns[i])).DataField).InnerText;
                    table += value + "</td></tr>";
                    //childnode.SelectSingleNode("/Data/" );                       
                    //ds.ReadXml(XmlReader.Create(new System.IO.StringReader(childnode.FirstChild.OuterXml)));
                    //}
                }
                table += "</table>";
                //string ss = Server.HtmlEncode(table);
                e.Row.Cells[i].Attributes.Add("onmouseover", "showdivByCs("" + table + "")");
                e.Row.Cells[i].Attributes.Add("onmouseout", "Remove()");
            }
        }
    }

javascript 裡的內容

//滑鼠經過時候顯示div   
function showdivByCs(table) ...{

//    table=table.replace("&amp;","&");
//    table=table.replace("&gt;",">");
//    table=table.replace("&lt;","<");
//    table=table.replace("&quot;",""");
//    table=table.replace("&apos;","'");

var x = window.event.x;
var y = window.event.y;
var show = document.getElementById("ShowInfo");
show.style.visibility = "visible";
show.style.top = y;
show.style.left = x;
show.style.background="#ffff00";

//讀取xml
document.getElementById("sp").innerHTML=table;

//div跟隨滑鼠
document.onmousemove = moveToMouseLoc;

}

//滑鼠移動時候div跟隨
function moveToMouseLoc(e)
...{
    x = window.event.x;
    y = window.event.y;
  var show = document.getElementById("ShowInfo");
  show.style.left = x;
  show.style.top = y;
  return true;
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.