This is a migrated thread and some comments may be shown as answers.

only last column display both text and image

1 Answer 42 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lynn
Top achievements
Rank 1
Lynn asked on 10 Jan 2012, 07:43 AM
Hi,

I have a radgrid, and I would like to display both text and image on the header. So I used following code to add a image to each of columns. But only last column displays both text and image, other columns still not display image.

 protected void RadGrid_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridHeaderItem)
            {
                GridHeaderItem headerItem = (GridHeaderItem)e.Item;
                HashSet<string> columnNames = (HashSet<string>)ViewState["Columns"];
                foreach (string columnName in columnNames)
                {
                    Image image = new Image();

                   image.ImageUrl = columnName + ".png";                     headerItem[columnName].Controls.Add(image);                 }             }         }
Could some one help me with displaying both text and image for each of the columns? Thanks very much.




1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 10 Jan 2012, 07:57 AM
Hello Lynn,

Try the following code.
C#:
protected void grid_ItemDataBound(object sender, GridItemEventArgs e)
{
 if (e.Item is GridHeaderItem)
 {
  GridHeaderItem itm = (GridHeaderItem)e.Item;
  foreach (TableCell cell in itm.Cells)
  {
     Image img = new Image();
     img.ImageUrl = "~/Images/Button.gif";
     cell.Controls.Add(img);
  }
 }
}

Thanks,
Princy.
Tags
Grid
Asked by
Lynn
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or