+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / add column in RadGrid dependent on a value

add column in RadGrid dependent on a value

4 posts, 0 answered
  1. Pik Lee
    Pik Lee avatar
    142 posts
    Registered:
    13 Aug 2012
    28 May 2010
    Link to this post
    I have a radgrid that is connected to SQLDataSource1. I want to add another SQLDataSource2 to check if the value result in SQLDataSource2 exist in SQLDataSource1. If the result does not exist in SQLDataSource1, I want to show text "New" in the RadGrid. Can this be solved? Can you show me an example?

    Thanks,
    Pik
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    31 May 2010
    Link to this post
    Hello Pik Lee,

    It depends on how you are binding the RadGrid and there you want to show this "New". You could try the following

    Bind the RadGrid on Page_Load. Here call a method where you create two instance of SqlDataSource control with the Select queries. Check the returned value in this method and decide which datasource you will use to bind the RadGrid control. Then show/hide CommandItemDisplay.

    sample code

    private void LoadData()
          {
              SqlDataSource ds1 = new SqlDataSource();
              ds1.ID = "DataSource1";
              ds1.ConnectionString = ConfigurationManager.ConnectionStrings["Sitefinity"].ToString();
              ds1.SelectCommand = "SELECT * FROM [sf_CmsContentBase] WHERE Application='/'";
             
     
              SqlDataSource ds2 = new SqlDataSource();
              ds2.ID = "DataSource2";
              ds2.ConnectionString = ConfigurationManager.ConnectionStrings["Sitefinity"].ToString();
              ds2.SelectCommand = "SELECT * FROM [sf_CmsContentBase] WHERE Application='/News'";
     
              //if(..some condition...)
              RadGrid1.DataSource = ds1;
              RadGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;
              // RadGrid1.DataSource = ds2;
          }
     
      protected void Page_Load(object sender, EventArgs e)
      {
     
          if (!IsPostBack)
          {
              LoadData();
              RadGrid1.DataBind();
          }
     }


    Greetings,
    Ivan Dimitrov
    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.
  3. Pik Lee
    Pik Lee avatar
    142 posts
    Registered:
    13 Aug 2012
    02 Jun 2010
    Link to this post
    Thanks for the info. 

    I have a RadGrid with a mastertable view and detailtables. I would like the data in the detailtables to show in the mastertable column not in hierarchy format. Can someone show me how to do that. Here is paart of the code.

    <mastertableview autogeneratecolumns="False" datakeynames="ed_id" datasourceid="SqlDataSource1">
    <DetailTables>
    <telerik:GridTableView runat="server" DataSourceID="SqlDataSource2" AllowSorting="False" AutoGenerateColumns="False" PageSize="7" Caption="Sales per Employee" Width="100%"><ParentTableRelation>
    <telerik:GridRelationFields MasterKeyField="ed_id" DetailKeyField="ed_id"></telerik:GridRelationFields>
    </ParentTableRelation>
    <Columns>
    <telerik:GridBoundColumn DataField="Employee_Id" HeaderText="Customer Name" SortExpression="ContactName" HeaderButtonType="TextButton" UniqueName="Employee_Id"></telerik:GridBoundColumn>
    </Columns>
    </telerik:GridTableView>
    </DetailTables>
    ...

    Thanks,
    Pik
  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    03 Jun 2010
    Link to this post
    Hi Pik Lee,

    You can take a look at the RadGrid for ASP.NET AJAX online demos. There are a number of demos - showing details in window for example. I am sure you will be able to find what you are looking for there.


    Kind regards,
    Radoslav Georgiev
    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.
Register for webinar
4 posts, 0 answered