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

RadGrid getCellByColumnUniqueName

3 Answers 375 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kent
Top achievements
Rank 1
Kent asked on 08 Dec 2010, 10:26 PM
I am having some trouble with getting a cell value when visible = false.  The innerHTML no longer returns the value.  Is there another solution?

When .MasterTableView.GetColumnSafe("ID").Visible = False is commented out it works correctly.  But, I need this column to be invisible.

With mGridEx
    .MasterTableView.GetColumnSafe("ID").Visible = False
    '    .MasterTableView.Rebind()
End With
<telerik:RadScriptManager ID="ScriptManager" runat="server" />
<telerik:RadGrid ID="RadGrid" runat="server" Width="100%" Height="90%"
    Font-Names="Verdana" GridLines="None" AllowSorting="True" ShowGroupPanel="True" 
    Skin="Office2007" AllowPaging="True" PageSize="50" AutoPostBack="True"
    <MasterTableView>
    </MasterTableView>
    <ClientSettings AllowDragToGroup="True"
        <Selecting AllowRowSelect="True" />
        <Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="True"
        </Scrolling> 
        <ClientEvents OnRowDblClick="RowDblClick" />
    </ClientSettings> 
</telerik:RadGrid>
<script type="text/javascript">
    function RowDblClick(sender, args) {
        var grid = sender;
        var MasterTable = grid.get_masterTableView();
        var row = MasterTable.get_dataItems()[args.get_itemIndexHierarchical()];
        var cell = MasterTable.getCellByColumnUniqueName(row, "ID");
        var value = cell.innerHTML
  
        alert("ID for this Row is: " + value);    
    }
</script>

 

 

 

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 Dec 2010, 05:46 AM
Hello Kent,

If you set the columns visible property to 'False' at server side, you cannot access the column value at client side. Because the control is not renderd when setting its visibility as false. You can overcome this problem by setting the Display property of column as 'False'.

RadGrid1.MasterTableView.GetColumnSafe("ID").Display = False

Thanks,
Princy.
0
Kent
Top achievements
Rank 1
answered on 09 Dec 2010, 06:24 AM

Ok that worked for eliminating the ID column from view, but now the rest of the columns seem to have lost their width formatting.  All of  the columns are now much wider than they need to be.  Prior to this change the autoformatting has been pretty impressive.

I have tried it in all different areas of this function (before IsPostBack, inside, before / after .DataBind) all with the same results.

#Region " FormatGrid..."
    Protected Overridable Sub FormatGrid()
        Try
            With mGridEx
                .DataSource = mDs
                If Not IsPostBack() Then
                    .Font.Name = "Verdana"
                    .Font.Size = New WebControls.FontUnit("8.5pt")
                End If
                .DataBind()
                .MasterTableView.GetColumnSafe("ID").Display = False
            End With
        Catch ex As System.NullReferenceException
        Catch ex As Exception
        End Try
    End Sub
#End Region

0
Daniel
Telerik team
answered on 14 Dec 2010, 11:42 AM
Hello Kent,

If you add this column to the datakeynames you will be able to extract its value on the client:
<MasterTableView DataKeyNames="ID" ClientDataKeyNames="ID">

<script type="text/javascript">
    function RowDblClick(sender, args)
    {
        var grid = sender;
        var MasterTable = grid.get_masterTableView();
        var row = MasterTable.get_dataItems()[args.get_itemIndexHierarchical()];
        var value = row.getDataKeyValue(ID");
 
        alert("ID for this Row is: " + value);
    }
</script>

I hope this approach is suitable for you

Regards,
Daniel
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Kent
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Kent
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or