Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Actually I have filled the gridview with data but i have so many columns so if user hover the cursor on any row
the data which are available in that row should be displayed in tooltip or like that



What i have tried is not working please help me

What I have tried:

<div style="height: 450px; width: 100%">
<asp:GridView ID="gv" runat="server" AutoGenerateColumns="False" CssClass="mGrid"
AlternatingRowStyle-CssClass="alt" GridLines="None" OnRowDataBound="gv_RowDataBound">
<columns>
<asp:BoundField DataField="Column1" HeaderText="C1" />
<asp:BoundField DataField="Column2" HeaderText="C2" />
<asp:BoundField DataField="Column3" HeaderText="C3" />
</columns>
</asp:GridView>
</div>
< div id="divDetail">
</div>
~~~~~~~~~~~~~~~~~~~~~~~~~
var iRowIndex;
function MouseEvents(objRef, evt, desc) {
if (evt.type == "mouseover") {
objRef.style.cursor = 'pointer';
objRef.style.backgroundColor = "#EEE";
ShowDiv(desc, evt.pageY);
}
else {
objRef.style.backgroundColor = "#FFF";
iRowIndex = objRef.rowIndex;
HideDiv();

}
}
function ShowDiv(desc, pos) {
document.getElementById('divDetail').style.display = 'block';
document.getElementById('divDetail').innerHTML = desc;
document.getElementById('divDetail').style.marginTop = pos - 25 + 'px';
}
function HideDiv() {
document.getElementById('divDetail').style.display = 'none';
}
function highlight(objRef, evt) {
if (evt.type == "mouseover") {
objRef.style.display = 'block';
document.getElementById('gv').rows[iRowIndex].style.backgroundColor = "#EEE";
}
else {
if (evt.type == "mouseout") {
document.getElementById('gv').rows[iRowIndex].style.backgroundColor = "#FFF";
objRef.style.display = 'none';
}
}
}

---------------------------
protected void gv_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string sDetails = System.String.Empty;
sDetails = "Details";
sDetails = sDetails + "Name: " +
DataBinder.Eval(e.Row.DataItem, "Column1").ToString() + "";
sDetails = sDetails + "Dept: " +
DataBinder.Eval(e.Row.DataItem, "Column2").ToString() + "";
sDetails = sDetails + "Desig: " +
DataBinder.Eval(e.Row.DataItem, "Column3").ToString() + "";
}
}
Posted
Updated 7-Nov-18 4:02am
v3

JavaScript isn't really required not unless if you want a fancy tooltip. In general, you can simply do something like this at RowDataBound event:

C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
            if (e.Row.RowType == DataControlRowType.DataRow) 
            { 
                ViewState["OrigData"] = e.Row.Cells[0].Text; 
                if (e.Row.Cells[0].Text.Length >= 30) //Just change the value of 30 based on your requirements 
                { 
                    e.Row.Cells[0].Text = e.Row.Cells[0].Text.Substring(0, 30) + "..."; 
                    e.Row.Cells[0].ToolTip = ViewState["OrigData"].ToString(); 
                }

             }

} 
 
Share this answer
 
tq for replay Vincent Maverick Durano

referred below

Link[^]
 
Share this answer
 
Comments
Vincent Maverick Durano 13-Nov-18 11:09am    
Please don't post your reply as solution. Use the comment button instead below the solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900