Can I access columns from the datasource that are not in the grid?

2 posts, 0 answers
  1. Dana Cobb
    Dana Cobb avatar
    46 posts
    Member since:
    Mar 2007

    Posted 19 Oct 2012 Link to this post

    I have 2 columns in my datasource(not in the grid) that I want to access in order to format columns that I do have in the grid. I am applying my formatting in the ItemDataBound event.
    Let's say my datasource has 4 columns. Select Field1, Field2, Field3, Field4 from myTable. In the grid I have Field1 with Unique column name "Field1" and Field2 with Unique column name "Field2". Can I access Field3 and Field4 from the datasource(not the grid) and format Field1 and Field2 with values that I analyze  in fields 3 and 4?
    I know I can access Fields 3 and 4 if I put them in the grid with "display=false", but I fear this just adds more unecessary html in the grid(and I have 8 grids on the form). I seem to remember something about accessing the MasterTableView, but I can't find the post anywhere.

    Thanks in advance,

    Dana Cobb
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 22 Oct 2012 Link to this post


    Please take a look into following code snippet I tried.

    <telerik:RadGrid ID="RadGrid1" runat="server" OnItemDataBound="RadGrid1_ItemDataBound" OnNeedDataSource="RadGrid1_NeedDataSource" AutoGenerateColumns="false">
                <telerik:GridBoundColumn DataField="OrderId" UniqueName="OrderID">

    protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        string selectQuery1 = "select top 10 OrderID,CustomerID,EmployeeID from Orders";
        SqlDataAdapter adapter1 = new SqlDataAdapter(selectQuery1, conn);
        RadGrid1.DataSource = dt1;
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        if (e.Item is GridDataItem)
            GridDataItem ditem = (GridDataItem)e.Item;
            foreach (DataRow row in dt1.Rows)
                string cellData = row["EmployeeID"].ToString();
                if (cellData == "2")
                    string order = row["OrderID"].ToString();
                    if (ditem["OrderID"].Text == order)
                        ditem["OrderID"].Text = "Hello";

  3. DevCraft R3 2016 release webinar banner
Back to Top