iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
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.
Here is a simple example demonstrating my problem:
<ISWebGrid:WebGrid ID="WebGrid1" Height="300px" Width="100%" UseDefaultStyle="True" runat="server" > <RootTable> <Columns> <ISWebGrid:WebGridColumn Name="col1" Bound="false" ColumnType="Template"> <CellTemplate> <asp:TextBox ID="txt1" runat="server" /> </CellTemplate> </ISWebGrid:WebGridColumn> </Columns> </RootTable> </ISWebGrid:WebGrid>
Code-behind:
protected void Page_Load(object sender, EventArgs e) { WebGrid1.InitializeRow += 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(); // <-- always comes back null TextBox txt1 = (TextBox)cell.FindControl("txt1"); } }
The problem is that the call to GetTemplateContainer() always returns null and i can't figure out why.
What am I doing wrong?
Thanks in advance,
Mike
Hello Mike,
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.
Regards,Riendy
Hi Mike,
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.
Hope this helps.Riendy
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname