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

Record cannot be inserted

1 Answer 54 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Darren
Top achievements
Rank 2
Darren asked on 06 Feb 2009, 01:44 PM
Hi,

I've got a radgrid linked to a LINQDatasource. I have allowed automoatic update,delete and insert. Taken off autogenerate columns.
Everything was working fine, then my superior wanted the text box longer for one column so i created this column
            <telerik:GridTemplateColumn HeaderText="WebsiteUrl" 
                DataType="System.String" UniqueName="WebsiteUrl" DataField="tblWebsite.WebsiteUrl" > 
                    <EditItemTemplate> 
                        <asp:TextBox ID="TextBoxWebsiteUrl" runat="server"  
                            Text='<%# Eval("WebsiteUrl") %>' Width="275px" 
                             
                            >                             
                            </asp:TextBox> 
                    </EditItemTemplate> 
                     
                    <ItemTemplate> 
                         
                        <asp:Label ID="LabelWebsiteUrl" runat="server" Text<%#Eval("WebsiteUrl")%></asp:Label> 
                         
                    </ItemTemplate> 
                </telerik:GridTemplateColumn>   
Now when i want to do an INSERT i get this error.
Website cannot be inserted. Reason: Cannot insert the value NULL into column 'WebsiteUrl', table 'cknetispservices.dbo.tblWebsite'; column does not allow nulls. INSERT fails. The statement has been terminated.

Please help.
D


1 Answer, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 09 Feb 2009, 04:53 PM
Hello Darren,

To implement two-way binding, you need to use Bind expression for your texbox editor instead of Eval, namely:

<EditItemTemplate>  
    <asp:TextBox ID="TextBoxWebsiteUrl" runat="server"   
      Text='<%# Bind("WebsiteUrl") %>' Width="275px">                              
    </asp:TextBox>  
</EditItemTemplate>  

Furthermore, note that you can customize the appearance of the textbox editor for standard GridBoundColumn using declarative style editors (instead of replacing it with GridTemplateColumn). Review the topic linked below for more details:

http://www.telerik.com/help/aspnet-ajax/grdstylingthroughdeclarativecustomeditors.html

Kind regards,
Sebastian
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Darren
Top achievements
Rank 2
Answers by
Sebastian
Telerik team
Share this question
or