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

How to re-set width of master table view in javascript??

1 Answer 157 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Fatima asked on 19 Feb 2009, 06:45 AM
Hi All!

I have made the grid scrollable and set the width of master table to "96%" n table layout = auto.
1. This is to avoid horizontal scrollbar when its vertically scrollable. But when my grid contains only 2-3 items i want to reset this width to 100% through javascript. How can i do this.

2. There is another question, i wanted to set headers fixed, but when i do this.. my grid looks very odd in terms of row height n width. Also there comes an unknown patch sort of at the end of row header and. my itemtemplate column dissappeares where i m displaying radio buttons. Any solution??


1 Answer, 1 is accepted

Sort by
Telerik team
answered on 23 Feb 2009, 12:59 PM
Hello Fatima,

1. You can reset the MasterTableView's width to 100% like this:

<%@ Page Language="C#" %> 
<%@ Import Namespace="System.Data" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<script runat="server"
protected void RadGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) 
    DataTable dt = new DataTable(); 
    DataRow dr; 
    int colsNum = 4
    int rowsNum = 2
    string colName = "Column"
    for (int j = 1; j <= colsNum; j++) 
        dt.Columns.Add(String.Format("{0}{1}", colName, j)); 
    for (int i = 1; i <= rowsNum; i++) 
        dr = dt.NewRow(); 
        for (int k = 1; k <= colsNum; k++) 
            dr[String.Format("{0}{1}", colName, k)] = String.Format("{0}{1} Row{2}", colName, k, i); 
    (sender as RadGrid).DataSource = dt
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<html xmlns=""
<head runat="server"
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
<title>RadControls for ASP.NET AJAX</title> 
<form id="form1" runat="server"
<asp:ScriptManager ID="ScriptManager1" runat="server" /> 
    <MasterTableView Width="90%" /> 
        <Scrolling AllowScroll="true" UseStaticHeaders="true" /> 
        <ClientEvents OnGridCreated="GridCreated" /> 
<script type="text/javascript"
function GridCreated(sender, args) 
    var masterTableHeader = sender.get_masterTableViewHeader().get_element(); 
    var masterTable = sender.get_masterTableView().get_element(); 
    if (masterTable.clientHeight < masterTable.parentNode.clientHeight
    { = "0px" = "16px" = "100%" = "100%" = "auto" = "auto"

2. We will need your RadGrid declaration to see what's going on exactly.

the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question