how to get the radgrid mastertableview column name on client side

7 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.

Back to Top