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

Edit width of textboxes in a ragrid column, programatically at runtime.

1 Answer 70 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nicklas
Top achievements
Rank 1
Nicklas asked on 26 Jun 2013, 06:52 AM
Hello!

When I enter edit mode in a Telerik radgrid I end up with all the textboxes beeing in different width.

I thought of solving this, by looping through all the items that is beeing edited and set them to System.Web.UI.WebControls.Unit.Pixel(300); to change the size. But I am doing something wrong here, I can't get it to work? And I want to refrain from using the getColumnEditor.

I thought of using it like this: But I cannot get it to work. Any idea?

protected void radgrid1_ItemCreated(object sender, GridItemEventArgs e)
       {
           if (e.Item is GridEditableItem && e.Item.IsInEditMode)
           {
               //the item is in edit mode   
               GridEditableItem editedItem = e.Item as GridEditableItem;
               editedItem.Width = Unit.Pixel(300);
               editedItem.Height = Unit.Pixel(300);
                
           }
       }

Any idea what to do to make them into the same size? 

On a side note, a total different question, Is it possible to set .Enabled status (ReadOnly) programatically without knowing what type the column is?

At the moment I am just stuck with having to iterate through and check whether the column textbox is a GridTextBoxColumnEditor  / GridNumericColumnEditor and so forth. It's annoying way to solve it.

Eg.   
if (columnEditor is GridTextBoxColumnEditor)
{
    GridTextBoxColumnEditor item = columnEditor as GridTextBoxColumnEditor;
    item.TextBoxControl.Enabled = false;
    // To hide completely item.TextBoxControl.ReadOnly = statusReadable ? false : true;

else if (columnEditor is GridNumericColumnEditor)
{
GridNumericColumnEditor item = columnEditor as GridNumericColumnEditor;
item.NumericTextBox.Enabled = false;

}          

See? I even have to specify NumericTextBox so I can't make generic solution to this? Anyone knows?


Sorry for having two questions in one thread, hope it is OK.

Best Regards 
Nicklas        



1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 28 Jun 2013, 05:33 PM
Hi Nicklas,

By default the sizes for all TextBox controls in the edit form of the RadGrid are equal. Try disabling all Css styles you have for the page and see if the behavior still persists. If the issue is still observed could you share full source code with the code-behind, so we could better understand your scenario?

About your second question. You could change the settings for the columns at runtime. In order to do this you should use the PreRender event handler for the RadGrid. In it you could iterate through the columns and set the properties you would like. The method is illustrated in the last section of this article.

I hope this would be helpful to you.

Regards,
Viktor Tachev
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Nicklas
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or