Solved

Access each column in a radgrid (Telerik) and set ItemStyle.Width (ItemDatabound)

Posted on 2013-06-25
2
2,727 Views
Last Modified: 2013-06-25
Hello!

I'm having problems with accessing a radgrids columns manually added from source code, I have loads of columns, and I don't want to repeat myself, adding the Width and change the headertext, according to my algorithm manually on each column.

Therefore I've been trying to find a way to set them automatically in the codebehind, however I am having problems accessing all the columns and settings.

The columns is as said not generated automatically.

Any idea?

Before When I have had the columns auto generated I have easily achieved this by using the Event ColumnCreated

 protected void radGrid_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
{
                e.Column.HeaderStyle.Width = 200;
                e.Column.ItemStyle.Width = 200;
                e.Column.HeaderText = "test";
               e.Column.UniqueName = "test2"
}

Now I want to do the same but with manually added columns? (The ColumnCreated event is only triggered when the columns are auto generated, sadly =()

So something like this, by what I assume listening to the ItemDataBound event?

protected void radGrid_ItemDataBound(object sender, GridItemEventArgs e)
{
      //Set column Width and Height and also the columns Header text and Unique name.
 }


Appreciate any help :) Hope I made it clear enough to understand :)
0
Comment
Question by:clooak
  • 2
2 Comments
 

Accepted Solution

by:
clooak earned 0 total points
ID: 39274319
Solved it myself using the PreRender event connected to the gridview

Eg.

protected void RadGrid1_PreRender(object sender, EventArgs e)          
{
        foreach (GridColumn col in RadGrid1.Columns)
        {
          col.HeaderStyle.Width = 600;
        }
}
0
 

Author Closing Comment

by:clooak
ID: 39274321
Solved it myself (see reply marked as answer)
0

Featured Post

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question