Cannot add gridpanel columns on server side

  1. #1

    Cannot add gridpanel columns on server side


    Add a script manager and viewport to the page. Add a grid panel to the center region. Add the column model. In the code behind try to add another column like this:



    Dim col As New Coolite.Ext.Web.Column()


    col.Header = "testing"


    col.Width = 75


    col.Sortable = True


    col.DataIndex = "test"


    GridPanel1.ColumnModel.Columns.Add(col)

    doesn't work. Any ideas?
  2. #2

    RE: Cannot add gridpanel columns on server side

    Hi cmschick,

    The following appears to work correctly for me. Can you expand on this sample a post an update which reproduces the problem?

    Example

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
        private object[] TestData
        {
            get
            {
                DateTime now = DateTime.Now;
                return new object[]
                {
                    new object[] {"Company 1", 0.1},
                    new object[] {"Company 2", 0.2},
                    new object[] {"Company 3", 0.3},
                    new object[] {"Company 4", 0.4},
                    new object[] {"Company 5", 0.5}
                };
            }
        }
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!Ext.IsAjaxRequest)
            {
                Column col = new Column();
                col.Header = "Price";
                col.DataIndex = "price";
                
                this.GridPanel1.ColumnModel.Columns.Add(col);
                
                this.Store1.DataSource = this.TestData;
                this.Store1.DataBind();
            }
        }
    
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>GridPanel with new Column - Coolite Toolkit Example</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ScriptManager ID="ScriptManager1" runat="server" />
            
            <ext:Store ID="Store1" runat="server">
                <Reader>
                    <ext:ArrayReader>
                        <Fields>
                            <ext:RecordField Name="company" />
                            <ext:RecordField Name="price" />
                        </Fields>
                    </ext:ArrayReader>
                </Reader>
            </ext:Store>
            
            <ext:GridPanel ID="GridPanel1" runat="server" StoreID="Store1" Height="300">
                <ColumnModel>
                    <Columns>
                        <ext:Column Header="Company" DataIndex="company" />
                    </Columns>
                </ColumnModel>
            </ext:GridPanel>
        </form>
    </body>
    </html>
    Geoffrey McGill
    Founder
  3. #3

    RE: Cannot add gridpanel columns on server side

    Hi Geoffrey,

    Thank you for the quick reply. As it turns out I believe this was basically a designer error. I dropped a gridpanel on the center region (in one of the default tabs) of the viewport in the designer. The error I received at run-time was something like 'Cannot add type Coolite.Ext.Web.Column to tab'. What lead me to believe it was a problem adding a column in the code behind is because although the grid did not render prior to my adding a column, it did not produce an error until I tried to add a column in the code behind. After I found the example of adding a grid to a tab all was well. Thanks again for your quick reply.

Similar Threads

  1. [CLOSED] Get visible GridPanel columns from server side
    By jmcantrell in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Feb 20, 2013, 12:22 AM
  2. To loop GridPanel rows server side
    By nanomusty in forum 1.x Help
    Replies: 7
    Last Post: Jun 28, 2012, 1:24 PM
  3. GridPanel Cell Value at Server Side
    By Ganesh3.shirsath in forum 1.x Help
    Replies: 1
    Last Post: Sep 29, 2010, 3:01 PM
  4. Replies: 0
    Last Post: Sep 20, 2010, 11:45 AM
  5. Save the GridPanel Server Side
    By egodoy in forum 1.x Help
    Replies: 0
    Last Post: May 27, 2009, 1:17 PM

Posting Permissions