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

I would get GridBoundColumn origin value

5 Answers 267 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jia
Top achievements
Rank 1
Jia asked on 10 Jul 2010, 06:44 PM
I use RadGrid contorls , it include a BoundColumn. I set DataFormatString="{0:C}", GridColumn Show is "$10.00", I use RadDataItem["money"].text get value "$10.00",Data origin value is "10", I want get value "10",why do?

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 12 Jul 2010, 10:08 AM
Hello Jia,

If you want to access the value in ItemDataBound event, then you can directly access the value using DataRowView object.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
      if (e.Item is GridDataItem)
       {
           DataRowView groupDataRow = (DataRowView)e.Item.DataItem;
           string value = groupDataRow["money"].ToString();
       }
    }

In the case of any other event, format the string by removing the '$' symbol from code behind which is shown below.

ASPX:
<telerik:GridBoundColumn DataField="money" DataFormatString="{0:C}"  UniqueName="money">
</telerik:GridBoundColumn>

C#:
string v = item["money"].Text;
v = v.Split('$')[1];


Thanks,
Princy.
0
John Hutchinson
Top achievements
Rank 1
answered on 21 Jun 2011, 12:44 PM
Is it safe to say, then, that once data binding occurs that the backing values are no longer available in their 'raw' form?
0
Radoslav
Telerik team
answered on 24 Jun 2011, 08:03 AM
Hello John,

You could get the 'raw' values from the original data source object from the e.Item.DataItem. DataItem property keeps the original object to which the RadGrid's row is bound. The values into this object are not formatted yet (by DataFormatString property).
However if you want to get the formatted value not the original(for example in your case 10 is the original value $10.00 is the formatted value) you could get it directly from the cell text:
string formattedText =(e.Item as GridDataItem)["ColumnUniqueName"].Text

Additionally you could get the original values on every event which occurs after ItemDataBound for example on RadGrid.PreRender:
void RadGrid1_PreRender(object sender, EventArgs e)
   {
       object o = RadGrid1.MasterTableView.Items[0].DataItem;
   }

I hope this helps.

All the best,
Radoslav
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Snehal
Top achievements
Rank 1
answered on 04 Mar 2013, 07:10 AM
Hi,
This is my code. In this at page load in grid lblCrDr
color should get changed but color is not getting changed so I want solution for this please help me.


if (e.Item is GridDataItem)
                {
                    GridDataItem item = e.Item as GridDataItem;
                    double Balance;
                    double CumBalance;
                    double.TryParse(item["Balance"].Text, out Balance);
                    double.TryParse(item["CumBalance"].Text, out CumBalance);
                    Label lblCrDr = new Label();
                    if (Balance >= 0)
                    {
                        lblCrDr.Text = " (Dr)";
                        item["Balance"].Text = item["Balance"].Text + lblCrDr.Text;
                        lblCrDr.ForeColor = System.Drawing.Color.Gray;
                    }
                    else
                    {
                        lblCrDr.Text = " (Cr)";
                        item["Balance"].Text = item["Balance"].Text + lblCrDr.Text;
                        lblCrDr.ForeColor = System.Drawing.Color.Red;
                    }
                    if (CumBalance >= 0)
                    {
                        lblCrDr.Text = " (Dr)";
                        item["CumBalance"].Text = item["CumBalance"].Text + lblCrDr.Text;
                        lblCrDr.ForeColor = System.Drawing.Color.Gray;
                    }
                    else
                    {
                        lblCrDr.Text = " (Cr)";
                        item["CumBalance"].Text = item["CumBalance"].Text + lblCrDr.Text;
                        lblCrDr.ForeColor = System.Drawing.Color.Red;
                    }

0
Shinu
Top achievements
Rank 2
answered on 04 Mar 2013, 08:57 AM
Hi,

Try accessing the label as shown below.
C#:
void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{  
 if (e.Item is GridDataItem)
 {
            GridDataItem item = e.Item as GridDataItem;
            Label lbl = (Label)item.FindControl("Label1");
 }
}

Thanks,
Shinu
Tags
Grid
Asked by
Jia
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
John Hutchinson
Top achievements
Rank 1
Radoslav
Telerik team
Snehal
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or