DataGrid and ToolTip

Discussion in 'ASP .Net Datagrid Control' started by René Nordby, Jun 1, 2004.

  1. René Nordby

    René Nordby Guest

    I have a DataGrid with some TemplateColumns. One of these columns is a
    CheckBox column, and the ChackBox have a ToolTip.

    This application should run in several languages, why the ToolTip should be
    changed dynamically.

    I have solved this by changing the ToolTip in the ItemDataBound event, like

    Private Sub myDataGrid_ItemDataBound(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.DataGridItemEventArgs) Handles

    If e.Item.ItemIndex <> -1 Then
    CType(e.Item.FindControl("myCheckBox"), CheckBox).ToolTip = "My new ToolTip"
    End If

    End Sub

    And everything works fine, but could it be done in another way.

    What I'm thinking about is, that the CheckBox column is a multiple instance
    of one CheckBox, so it feels a little stupid to change the ToolTip for each
    Item in the DataGrid.

    It should be possible to change the ToolTip before I make my databinding, so
    I only should do it once, but...?

    Please give me a hint...

    René Nordby
    René Nordby, Jun 1, 2004
    1. Advertisements

  2. René Nordby

    Amar Guest

    Why don't you pass as a parameter the tooltip string you want to
    display at ctor of the template column so every checkbox is created
    has the correct tooltip.
    Amar, Jun 2, 2004
    1. Advertisements

  3. René Nordby

    René Nordby Guest


    Thanks for your reply, but I'm not sure about what you mean, so could you
    please give an code example.
    René Nordby, Jun 2, 2004
  4. René Nordby

    Amar Guest

    I assume you create the template column in the code behind of GRID
    like this...

    TemplateColumn tc = new TemplateColumn();
    tc.ItemTemplate = new GridItemCheckBoxTemplate("ToolTipText");
    tc.HeaderStyle.Wrap = false;
    tc.ItemStyle.Wrap = false;

    on the constructor of the template column....
    this is a sample of my code so you will see some things that you want

    public class GridItemCheckBoxTemplate : System.Web.UI.ITemplate{

    private string mToolTip;

    public GridItemCheckBoxTemplate(string tooltip){

    public void InstantiateIn(System.Web.UI.Control container){
    CheckBox lc = new CheckBox();
    lc.ToolTip = mToolTip;
    lc.EnableViewState = true;
    lc.DataBinding += new EventHandler(BindCol);
    Literal startLC = new Literal();
    startLC.Text = "<TABLE width=100% border=0 cellspacing=0
    cellpading=0><TR><TD align=center>";
    Literal endLC = new Literal();
    endLC.Text = "</TD></TR></TABLE>";
    Amar, Jun 3, 2004
  5. René Nordby

    René Nordby Guest

    No, I'm not creating the TemplateColumn in the code behind. I have created
    the column in the designer (Property Builder) in Visual Studio.Net. The only
    things that change in the column, beside the data, is the HeaderText and the
    ToolTip, so thats why I have created it on design time.

    So what I was looking for was a way to change the ToolTip on the CheckBox
    before the databinding, but I can't find a way to do that. It's seems that
    there are no way to get grap of the CheckBox and it's properties before
    databinding, or is there?
    René Nordby, Jun 3, 2004
  6. René Nordby

    Amar Guest

    I don't know i have never used template column from designer, and i
    don't have time to check it know, but i believe that there must be a
    way to access the template columns...
    Good luck.
    Amar, Jun 4, 2004
  7. René Nordby

    Rick Spiewak Guest

    If your Checkbox is templated, you should be able to bind the tooltip in the
    databindings collection in the designer for the column. The tooltip ideally
    would be in a column in your datasource to make this work.
    Rick Spiewak, Jun 5, 2004
  8. René Nordby

    René Nordby Guest

    Thanks, I have tryied it, and it works.

    But still, is there a way to get a reference to the templated CheckBox or
    any other control in a TemplateColumn in a DataGrid, before databinding, ex.
    in the Page_Load event?
    René Nordby, Jun 5, 2004
  9. René Nordby

    Rick Spiewak Guest

    You should be able to use .FindControl in the page load event, based on the
    item index of your choice.
    Rick Spiewak, Jun 16, 2004
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.