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

RadGrid - Get column width and append string if cell is empty

3 Answers 185 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Priya B
Top achievements
Rank 1
Priya B asked on 21 Jun 2010, 07:12 AM

I need to add the below functionality to all my grids

1. If the cell is empty, I need to append a value.
2. I need to get the Grid column width. (width is dynamic. I dint set any width specifically.)

I have inherited the RadGrid control and it executes both ItemDatabound/PreRender handler.
If I add the string, all the strings left empty. I tried the below code

protected override void OnPreRender(EventArgs e)
 {
 ControlHelper.RegisterScriptFile("~/App/script/NCRadGrid.js");
         
       
            foreach (GridItem item in MasterTableView.Items)
            {
             
                foreach (TableCell cell in item.Cells)
                {
                    cell.Text += " ";
                }
            }

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 21 Jun 2010, 09:13 AM
Hello Priya,

1. You can try the following code snippet to append some value when the cell is empty.
C#:
 
 protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
       foreach (GridItem item in RadGrid1.MasterTableView.Items) 
        { 
            foreach (TableCell cell in item.Cells) 
            { 
                if (cell.Text == " "
                { 
                    cell.Text += "Some value"
                } 
            } 
        } 
    } 

2.  As far as I know, it is not possible to access the column width from code if the width is not set. One possible approach would be accessing the column width on the client and storing the value in hidden input on the page. Then you can access the hidden input control from code behind to get the width of the column.

Check out the following Forum link which explains similar kind of scenario.
Retrieve column width on server side.

Thanks,
Princy.
0
Priya B
Top achievements
Rank 1
answered on 21 Jun 2010, 09:37 AM
Hello Princy,

As I mentioned in my earlier post, I need to append the value for all grids, present in my project not for single RadGrid.

I inherited the Radgrid Control and created the prerender function with it.

On the prerender event or on some other event, I need to append the value, if the cell value is empty.

From your example, still I am getting the empty value and the code is not genaralized. I couldn't pass the Radgrid object here.

I have only EventArgs as argument.

protected override void OnPreRender(EventArgs e)

{

 

 

--- code follows here
base
.OnPreRender(e);

 

}


Could you please provice any solution for this?
One sample Radgrid format follows here...

<

 

netcweb:NCRadGrid runat="server" ID="ActivityGrid"

 

 

OnNeedDataSource="ActivityGrid_NeedDataSource"

 

 

OnItemCreated="ActivityGrid_OnItemCreated"

 

 

PageSize="10" AllowPaging="true" SkinID="ActivityList"

 

 

OnPageSizeChanged="ActivityGrid_PageSizeChanged" >

 

 

<PagerStyle AlwaysVisible="true" />

 

 

<ClientSettings AllowGroupExpandCollapse="true" />

 

 

<GroupingSettings />

 

 

<MasterTableView AutoGenerateColumns="false" GroupLoadMode="client">

 

 

<Columns>

 

 

<telerik:GridTemplateColumn UniqueName="1" HeaderText="My courses student page">

 

 

<ItemTemplate>

 

 

<netcweb:PlaceHolderControl runat="server" ID="column1PlaceHolder">

 

 

</netcweb:PlaceHolderControl>

 

 

 

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

<telerik:GridTemplateColumn UniqueName="2" HeaderText="StudentCourseListStatusHeader">

 

 

<ItemTemplate>

 

 

<netcweb:PlaceHolderControl runat="server" ID="column2PlaceHolder">

 

 

</netcweb:PlaceHolderControl>

 

 

 

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

<telerik:GridTemplateColumn UniqueName="3" HeaderText="StudentCourseListDateHeader">

 

 

<ItemTemplate>

 

 

<netcweb:PlaceHolderControl runat="server" ID="column3PlaceHolder">

 

 

</netcweb:PlaceHolderControl>

 

 

 

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

<telerik:GridTemplateColumn UniqueName="4" HeaderText="">

 

 

<HeaderTemplate>

 

 

<netcweb:ImageCheckBoxControl runat="server" ID="DetailedListCheckBox"

 

 

OnCheckedChanged="DetailedListCheckBox_OnCheckedChanged" AutoPostBack="true"

 

 

SkinID="DetailedView" />

 

 

</HeaderTemplate>

 

 

<ItemTemplate>

 

 

<netcweb:PlaceHolderControl runat="server" ID="column4PlaceHolder">

 

 

</netcweb:PlaceHolderControl>

 

 

 

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

</Columns>

 

 

</MasterTableView>

 

 

</netcweb:NCRadGrid>

 


0
Dimo
Telerik team
answered on 21 Jun 2010, 11:05 AM
Hi Priya,

Please do not post the same question in two forum threads, as this makes tracking your support history more difficult.

Please navigate to:

http://www.telerik.com/community/forums/aspnet-ajax/grid/radgrid-show-gridlines-even-if-cell-is-empty.aspx


Dimo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Priya B
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Priya B
Top achievements
Rank 1
Dimo
Telerik team
Share this question
or