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

Grid data format issue

1 Answer 53 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mallikharjun Mulagundla
Top achievements
Rank 1
Mallikharjun Mulagundla asked on 14 Apr 2010, 02:51 PM

Hi,

We are binding the dataset to grid whose columns are auto generated (AutoGenerateColumns="true")

Column data format string can be either "$" or "%" which is depedent on combo selection format string is bound on column created event.

Initally data is shown with "%", changed the combo selection "$" on click of button format string is not changed to "$".

protected void radMainGrid_ColumnCreated(object sender, Telerik.Web.UI.GridColumnCreatedEventArgs e)  
        {  
            if (e.Column is GridBoundColumn)  
            {  
                GridBoundColumn boundColumn = e.Column as GridBoundColumn;  
                if (boundColumn.DataField.Equals("Name"))  
                {  
                    if(radView.SelectedValue != "0")  
                        boundColumn.FooterText = "Grand Total";  
                }  
                else if(!boundColumn.DataField.Equals("ID"))  
                {  
                    if (radView.SelectedValue != "0")  
                    {  
                        boundColumn.Aggregate = GridAggregateFunction.Sum;  
                        boundColumn.DataFormatString = "{0:C0}";  
                    }  
                    else  
                    {  
                        boundColumn.DataFormatString = "{0:P0}";  
                    }  
                }  
            }  
        }  
 

Please help me to resolve this issue.

Thanks, Mulagundla

Please help me to resolve this issue.Thanks, Mulagundla

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 15 Apr 2010, 09:36 PM
Hello Mallikharjun,

You can change the DataFormatString property on the SelectedItemChanged event on your combo box.
protected void RadComboBox1_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
{
    GridBoundColumn col = RadGrid1.MasterTableView.GetColumn("ID") as GridBoundColumn;
    col.DataFormatString = RadComboBox1.SelectedItem.Value == "0" ? "{0:C0}" : "{0:P0}";
    RadGrid1.Rebind();
}

I hope this helps.

Best regards,
Daniel
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
Mallikharjun Mulagundla
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or