Click here to Skip to main content
15,891,788 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi everyone,

i have a table.It has a fields like Id,Name,Description.I need to bind the data to gridview.for description column i need to show 150 charters in gridview, when ever user mouse over on thatdescrption column entire data should be displayed in tool tip.
can any one tell me please.here is my code.

thanking you,

XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server"
            onrowdatabound="GridView1_RowDataBound">
        </asp:GridView>
    </div>
    </form>
</body>
</html>


aspx.cs:
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{

if (!IsPostBack)
{
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Description", typeof(string));


DataRow dr = dt.NewRow();
dr[0] = 1001;
dr[1] = "sukumar";
dr[2] = "Hiiiiiiiiiii This is the sampleeeeeeee Testttttttttttt malilll";
dt.Rows.Add(dr);



DataRow dr2 = dt.NewRow();
dr2[0] = 1002;
dr2[1] = "amala";
dr2[2] = "Hiiiiiiiiiii This is the sampleeeeeeee Testttttttttttt malilll";
dt.Rows.Add(dr2);



DataRow dr1 = dt.NewRow();
dr1[0] = 1003;
dr1[1] = "akash";
dr1[2] = "Sampleeeeeeee This is the sampleeeeeeee Testttttttttttt malilll";
dt.Rows.Add(dr1);

GridView1.DataSource = dt;
GridView1.DataBind();
}
}

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.ToolTip = (e.Row.DataItem as DataRowView)["Description"].ToString();

}
}
Posted
Updated 27-Apr-14 22:33pm
v2
Comments
DamithSL 28-Apr-14 3:43am    
how you bind gridview? can you post aspx code for the gridview? haven't you try to set Tooltip='<%# Eval("Description") %>'> of control of ItemTemplate?
Bitto kumar 28-Apr-14 4:36am    
colud you please check my post,i have updated the question.i am able to show data in tooltip.but my requirement is description column should show 150 charaters only.when user mouse over on that column
entire msg should display in tooltip..
DamithSL 28-Apr-14 5:37am    
ok, please check my answer.
Bitto kumar 28-Apr-14 8:59am    
thank you so much it working fine as expected.once again thank's alot

<asp:gridview id="grdUserdata" runat="server" width="90%" ondatabound="grdUserdata_DataBound" xmlns:asp="#unknown">
<columns> <asp:templatefield headertext="Edit">
<itemtemplate>
<asp:imagebutton id="Imgbtnedit" runat="server" height="20px" tooltip="<%# Eval(" id")="" %&gt;"="">
ImageUrl="~/th.jpg" OnClick="Imgbtnedit_Click" Width="20px" />

<itemstyle horizontalalign="Center" verticalalign="Middle">

 
Share this answer
 
ASPX
ASP.NET
<asp:gridview id="GridView1" runat="server" onrowdatabound="GridView1_RowDataBound" autogeneratecolumns="False" xmlns:asp="#unknown">
    <columns>
        <asp:templatefield headertext="Id" sortexpression="Id">
            <itemtemplate>
                <asp:label id="Label1" runat="server" text="<%#Bind("Id") %>"></asp:label>
            </itemtemplate>
        </asp:templatefield>
        <asp:templatefield headertext="Name" sortexpression="Name">
            <itemtemplate>
                <asp:label id="Label2" runat="server" text="<%#Bind("Name") %>"></asp:label>
            </itemtemplate>
        </asp:templatefield>
        <asp:templatefield headertext="Description" sortexpression="Description">
            <itemtemplate>
                <asp:label id="Label3" runat="server" text=""></asp:label>
            </itemtemplate>
        </asp:templatefield>
        <asp:templatefield>
            <itemtemplate>
                <asp:hiddenfield id="HiddenField1" runat="server" value="<%# Bind("Description") %>" />
            </itemtemplate>
        </asp:templatefield>
    </columns>
</asp:gridview>


C# code
C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
       DataRowView drv =  e.Row.DataItem as DataRowView;
       Label test = e.Row.FindControl("Label3") as Label;
       if (drv["Description"].ToString().Length > 150)
       {
           test.Text = drv["Description"].ToString().Substring(0, 150) + "...";
       }
       else
       {
           test.Text = drv["Description"].ToString();

       }
       e.Row.ToolTip = drv["Description"].ToString();
    }
}
 
Share this answer
 
v2
http://www.aspdotnet-suresh.com/2013/05/jquery-show-gridview-row-details-in.html
 
Share this answer
 

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