﻿<?xml version="1.0" encoding="utf-8"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Intersoft Community - WebGrid Enterprise - How to add rows programmatically?</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-add-rows-programmatically/</link><description /><generator>http://www.intersoftsolutions.com</generator><language>en</language><copyright>Copyright 2002 - 2015 Intersoft Solutions Corp. All rights reserved.</copyright><ttl>60</ttl><item><title>How to add rows programmatically?</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-add-rows-programmatically/</link><pubDate>Mon, 06 Jun 2011 21:40:40 GMT</pubDate><dc:creator>Riendy</dc:creator><category>NullReferenceException</category><description>&lt;p&gt;Hi Mike,&lt;/p&gt;&lt;p&gt;You get a NullReferenceException because you're unable to use unbound here. The templating is only supported for bound columns. Which means it must be bound to a data. The WebGrid have to be bound to a datasource as well.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Hope this helps.&lt;br /&gt;Riendy&lt;/p&gt;</description></item><item><title>How to add rows programmatically?</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-add-rows-programmatically/</link><pubDate>Fri, 03 Jun 2011 07:20:07 GMT</pubDate><dc:creator>Riendy</dc:creator><category>NullReferenceException</category><description>&lt;p&gt;Hello Mike,&lt;/p&gt;&lt;p&gt;I have replicated your issue here. your issue have been forwarded to our development team for further investigated. I will let you know for any updates soon.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Riendy&lt;/p&gt;</description></item><item><title>How to add rows programmatically?</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-add-rows-programmatically/</link><pubDate>Thu, 02 Jun 2011 16:19:11 GMT</pubDate><dc:creator>mpeet</dc:creator><category>NullReferenceException</category><description>&lt;p&gt;I am new to this control.  I want to add rows to a WebGrid programmatically.  I want the WebGrid to be unbound from any database.  I want to use asp.net controls within the cells, so I am using templates.  I keep getting a NullReferenceException.&lt;/p&gt;
&lt;p&gt;Here is a simple example demonstrating my problem:&lt;/p&gt;
&lt;p /&gt;&lt;pre&gt;&amp;lt;ISWebGrid:WebGrid ID="WebGrid1" Height="300px" Width="100%" UseDefaultStyle="True" runat="server" &amp;gt;
    &amp;lt;RootTable&amp;gt;
        &amp;lt;Columns&amp;gt;
            &amp;lt;ISWebGrid:WebGridColumn Name="col1" Bound="false" ColumnType="Template"&amp;gt;
                &amp;lt;CellTemplate&amp;gt;
                    &amp;lt;asp:TextBox ID="txt1" runat="server" /&amp;gt;
                &amp;lt;/CellTemplate&amp;gt;
            &amp;lt;/ISWebGrid:WebGridColumn&amp;gt;
        &amp;lt;/Columns&amp;gt;
    &amp;lt;/RootTable&amp;gt;
&amp;lt;/ISWebGrid:WebGrid&amp;gt;&lt;/pre&gt;
&lt;p&gt; Code-behind:&lt;/p&gt;
&lt;p /&gt;&lt;pre&gt;    protected void Page_Load(object sender, EventArgs e)
    {
        WebGrid1.InitializeRow &amp;#43;= new RowEventHandler(WebGrid1_InitializeRow);
        WebGridRow row = WebGrid1.RootTable.CreateRow();
        WebGrid1.RootTable.Rows.Add(row);
    }
    void WebGrid1_InitializeRow(object sender, RowEventArgs e)
    {
        if (e.Row.Type == RowType.Record)
        {
            WebGridRow row = (WebGridRow)e.Row;
            WebGridCellTemplateContainer cell = row.Cells[0].GetTemplateContainer();    // &amp;lt;-- always comes back null
            TextBox txt1 = (TextBox)cell.FindControl("txt1");
        }
    }&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;The problem is that the call to GetTemplateContainer() always returns null and i can't figure out why.&lt;/p&gt;
&lt;p&gt;What am I doing wrong?&lt;/p&gt;
&lt;p&gt;Thanks in advance,&lt;/p&gt;
&lt;p&gt;Mike&lt;/p&gt;
&lt;p /&gt;
&lt;p /&gt;</description></item></channel></rss>