Displaying a tooltip in a datagrid cell, tough problem, can it be

G

Guest

I'm trying to work with a datagrid column in order to display a tooltip in a
datagrid cell. The reason I am doing this is because I have some long strings
being returned and I don't want the rows of the datagrid expaning down to
much. I basically want to display the first 50 characters in the grid cell
and then display the rest as a tooltip in the grid cell. I'm not sure if this
is possible but if anyone can help me do this I would be very grateful. I
have started this and am able to do the first part and get only the first 50
characters to be displayed back. I can also get the rest of the string set to
a new variable but I don't know how to use this properly and display a
tooltip with the string value for only that cell. Hope everyone knows what
i'm trying to do and that i've explained myself well enough. I've included
the code to show what I've down and also to give an idea of what i'm trying
to do. Any help at all would be very much appreciated.

HTML for the Column
<asp:TemplateColumn Visible="True" HeaderText="Start Date">
<ItemTemplate>
<%#getCompanyName(DataBinder.Eval(Container.DataItem,"CompanyName").ToString())%>
</ItemTemplate>
</asp:TemplateColumn>

Code Behind with comments of what I need to do

public string getCompanyName(string p_sFieldValue )
{
int iLength = p_sFieldValue.Length;
int iLengthToUse = 0;
int iRemainder = 0;

if (p_sFieldValue == DBNull.Value.ToString())
{
return string.Empty;
}
else if(iLength > 50)
{
//In here I basically would like to only return the first
//50 characters of the string and then for the rest of the
//string I’d like the details to be displayed in a tooltip
//for that cell. I know the below code won’t work because
//of the e but its just to give an idea of what I need to do.
//If someone knows how I can display a tooltip for the rest
//of the string I’d be really really grateful
//I’m not sure if this can be done but if anyone has any
//ideas I’d really appreciate it. Thanks
/*
iRemainder = p_sFieldValue.Length - 50;
string sTooltipText = p_sFieldValue.Substring(50,iRemainder);
if(e.Item.ItemType == ListItemType. SelectedItem)
{
e.Item.Cells[1].ToolTip = sTooltipText;
}
*/
//This bit works fine
string sCompanyName = p_sFieldValue.Substring(0,50); return
sCompanyName;
}
else
{
return p_sFieldValue;
}
}
 
G

Guest

Cheers what is it that this does exactly and do you know how I can use this
to display the tooltip. I do see where your coming from here though. How do I
bind to the column though. Do I remove the following or do I keep it in: -
(DataBinder.Eval(Container.DataItem,"CompanyName").ToString())

Sorry for all the questions I'm just really stuck on this one.
Thanks again for your input.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top