how to get the radgrid mastertableview column name on client side

9 posts, 0 answers
  1. Jas
    Jas avatar
    40 posts
    Member since:
    Mar 2008

    Posted 07 Dec 2008 Link to this post

    I create columns of my grid dynamically on the server side. These are not created on the client side.

    I need to check the name of the first column to this radgrid.
    How is this possible ?

    I actually tried

    var gridID = $find("<%=RadgridDataAval.ClientID %>");
    var x = gridID.get_masterTableView().getColumnByUniqueName("Error");
    if (x)
      alert ("exists");
    else
      alert("doesnt exist");

    Error is the name of one of the columns of the grid. However, says it doesn't exist

    Also, I don't know if we have examples that show how to fetch colulmn name of a particular column in the mastertableview on the client side.

    SOS

    thanks,
    Jas



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

    Posted 07 Dec 2008 Link to this post

    Hi Jas,

    I tried this on my end and it is working fine. Have you set the correct column UniqueName? I would suggest you send your aspx code.
    Here is the code I tried.

    ASPX:

    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" GridLines="None"
                <MasterTableView> 
                </MasterTableView> 
            </telerik:RadGrid> 

    CS:
    protected void Page_Load(object sender, EventArgs e) 
        { 
     
            if (!IsPostBack) 
            { 
                RadGrid1.DataSourceID ="SqlDataSource1"
                 
                RadGrid1.Width = Unit.Percentage(98); 
                RadGrid1.PageSize = 5; 
                RadGrid1.AllowPaging = true
                RadGrid1.AutoGenerateColumns = false
                RadGrid1.Skin = "Web20"
                RadGrid1.MasterTableView.PageSize = 15; 
                RadGrid1.MasterTableView.Width = Unit.Percentage(100); 
     
               //Add GridBoundColumn 
                GridBoundColumn boundColumn; 
                boundColumn = new GridBoundColumn(); 
                RadGrid1.MasterTableView.Columns.Add(boundColumn); 
                boundColumn.DataField = "ProductName"
                boundColumn.HeaderText = "ProductName"
                boundColumn.UniqueName = "ProductName"
            } 
        } 


    JS:
    <script type="text/javascript"
      function ShowColumnName() 
      { 
      alert('Hi'); 
      var gridID = $find("<%=RadGrid1.ClientID %>"); 
      var x = gridID.get_masterTableView().getColumnByUniqueName("ProductName"); 
      if (x) 
        alert ("exists"); 
      else 
      alert("doesnt exist"); 
     
      
      } 
     
    </script> 


    Thanks
    Shinu.

  3. Jas
    Jas avatar
    40 posts
    Member since:
    Mar 2008

    Posted 07 Dec 2008 Link to this post

    Hi Shinu,

    Actually I create a data table on the server side .

    DataTable ddt = new DataTable();
                    ddt.Columns.Add("ERRORCODE", typeof(string));

    and then set the data source of my radgrid equals to this data table.

    Then does it really set the unique name for the radgrid columns if i create my radgrid like this ?
    Just wondering . I really don't do it the way you created columns

    Thanks,
    Jas

  4. Jas
    Jas avatar
    40 posts
    Member since:
    Mar 2008

    Posted 07 Dec 2008 Link to this post

    Also,

    how do i get the name of all the columns of the radgrid on client side ? is there any way to do that ?

    Thanks
    Jas

  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 08 Dec 2008 Link to this post

    Hi Jas,

    I guess you have set AutoGenerateColumns to true. If so the name of the column will be the Column UniqueName.

    You can access all the columns in a Grid on the client side as shown below.


    ASPX:

     <input id="Button1" type="button" onclick="GetColumnNames();" value="button" /> 


    JS:
    <script type="text/javascript"
            
            function GetColumnNames() 
            { 
             var grid = $find("<%=RadGrid1.ClientID %>");  
             var columnCount = grid.get_masterTableView().get_columns().length; 
             for(var i=0;i<columnCount;i++) 
             { 
             var UniqueName=grid.get_masterTableView().get_columns()[i].get_uniqueName(); 
             alert(UniqueName) 
             } 
            } 
            </script> 

    Regards
    Princy

  6. Achuthan
    Achuthan avatar
    31 posts
    Member since:
    May 2007

    Posted 15 Oct 2012 Link to this post

    Hi,

    how do i get the name of all the columns of the radgrid in C#?


       protected void RadGrid1_DataBound(object sender, EventArgs e)
            {
                // Here i am trying to access the column names of Radgrid  for  implement the Multiple column header.
             
                var count= RadGrid1.Columns.Count;
             
               //but  the count value is always zero.
       
            }

  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 15 Oct 2012 Link to this post

    Hi,

    You can loop through the columns as shown below.
    C#:

    protected void Button1_Click(object sender, EventArgs e)
    {
      foreach (GridColumn col in RadGrid1.Columns)
      {
        string value = col.UniqueName.ToString();
      }
    }

    Thanks,
    Shinu.

  8. Sheshagiri
    Sheshagiri avatar
    4 posts
    Member since:
    Sep 2014

    Posted 15 Sep 2014 Link to this post

    Hi, 
    I have two table like Task and Task History,  with different column names for key reference(taskID(primary key in Task) and taskhID(foreign key in Task History) i want to bind this two table to  rad grid.
     
     Problem is,


    while binding if i use taskhID, then

    protected void radgv_OnDetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
        {

            GridDataItem dataitem = (GridDataItem)e.DetailTableView.ParentItem;

            if (e.DetailTableView.Name == "TaskHistory")
            {

                string id = dataitem.GetDataKeyValue("taskhID").ToString(); //error: Object reference not set to an instance of an object
                e.DetailTableView.DataSource = GetDataTable("SELECT * FROM TaskHistory where taskhID=  '" + id + "'");


            }
    Becouse column "taskID" is not exit in Table TaskHistory.
    Please tell me the solution.




  9. Eyup
    Admin
    Eyup avatar
    1792 posts
    Member since:
    Jan 2015

    Posted 18 Sep 2014 Link to this post

    Hello Sheshagiri,

    Can you please verify that the taskhID field is included in the DataKeyNames of the corresponding table view?
    http://demos.telerik.com/aspnet-ajax/grid/examples/data-binding/programmatic-hierarchy/defaultcs.aspx?#qsf-demo-source

    Looking forward to your reply.

    Regards,
    Eyup
    Telerik

     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     

Back to Top