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

get the desc of code value of field in telerik GridBoundColumn retrieved from asp ObjectDataSource

2 Answers 36 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Hadoop
Top achievements
Rank 1
Hadoop asked on 16 Aug 2015, 10:25 AM

I want to edit the value of field coming from ObjectDataSource. 
My sample code of aspx page:

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="SrchOrder"
    TypeName="ClsOrder">
    <SelectParameters>
        <asp:ControlParameter ControlID="Order Number" Name="order_id" PropertyName="Text" Type="String" />
        <asp:ControlParameter ControlID="Seller" Name="seller_name" PropertyName="Text" Type="String" />                           
    </SelectParameters>
</asp:ObjectDataSource>
 
<telerik:RadGrid ID="radGrid_srch_order"
    runat="server"
    PageSize="100"
    AllowSorting="false"
    AllowPaging="false"
    ShowFooter="false"
    ShowGroupPanel="false"
    HeaderStyle-HorizontalAlign="Center"
    HeaderStyle-Font-Bold="true"
    AutoGenerateColumns="false"                           
    DataSourceID="ObjectDataSource1">
    <MasterTableView AllowFilteringByColumn="False" AutoGenerateColumns="false" TableLayout="Auto">
       <Columns>
            <telerik:GridBoundColumn DataField="order_dt" AutoPostBackOnFilter="false" ItemStyle-HorizontalAlign="Center" HeaderText="Order Date" SortExpression="order_dt" AllowFiltering="false" UniqueName="order_dt" />   
            <telerik:GridBoundColumn DataField="seller_first_name" ItemStyle-HorizontalAlign="Center" HeaderText="seller First Name" SortExpression="seller_first_name" AllowFiltering="false" UniqueName="seller_first_name"  />     
            <telerik:GridBoundColumn DataField="seller_last_name" ItemStyle-HorizontalAlign="Center" HeaderText="seller Last Name" SortExpression="seller_last_name" AllowFiltering="false" UniqueName="seller_last_name" />
            <telerik:GridBoundColumn DataField="status" ItemStyle-HorizontalAlign="Center" HeaderText="Status" SortExpression="status" AllowFiltering="false" UniqueName="status" />
       </Columns>
    </MasterTableView>
</telerik:RadGrid>
 My code behind: 

protected void btnSearch_Click(object sender, EventArgs e)
    {       
         radGrid_srch_order.DataBind();
    }

The value of the field "status" that comes from database are {1, 2, 3, 4} where
1 desc undelivered
2 desc delivered
3 desc paid
4 desc unpaid
How can I show the desc of the status code in GridBoundColumn. I know it can be done from sql query but how can I do it using telerik?

2 Answers, 1 is accepted

Sort by
0
Accepted
Eyup
Telerik team
answered on 19 Aug 2015, 08:29 AM
Hello Hadoop,

First of all, please note that the NeedDataSource event is the mandatory way when you need to bind the grid to a programmatic data source in the code-behind. It is important to note that you are not using DataBind() to bind the grid. Performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, Grouping, Exporting, Paging, Sorting, Filtering, etc. require accommodating appropriate database operations.  Therefore, we suggest you to avoid Simple Databinding and strongly recommend the use of more advanced databinding methods, which automatically handle the aforementioned functions:
Declarative DataSource
Programmatic Data Binding

As for your original requirement, you can achieve that using the following approach:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = e.Item as GridDataItem;
        string value = DataBinder.Eval(item.DataItem, "ShipName") as string;
        string newText = string.Empty;
        switch (value)
        {
            case "Name 1": newText = "undelivered"; break;
            case "Name 2": newText = "delivered"; break;
            case "Name 3": newText = "paid"; break;
            case "Name 4": newText = "unpaid"; break;
            default: break;
        }
        item["ShipName"].Text = newText;
    }
}

Hope this helps. Please give it a try and let me know if it works for you.

Regards,
Eyup
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Hadoop
Top achievements
Rank 1
answered on 23 Nov 2015, 10:55 PM
Thank you so much for the clear explanation!!!!
Tags
Grid
Asked by
Hadoop
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Hadoop
Top achievements
Rank 1
Share this question
or