Update fails when using GridTemplateColumn

3 posts, 1 answers
  1. stevied
    stevied avatar
    37 posts
    Member since:
    Apr 2007

    Posted 30 Mar 2011 Link to this post

    I have a radgrid which is using GridTemplateColumn to enable me to manage the content the way I want.  The Grid worked when i was using GridBoundColumns but when i switch i'm getting the following error.

    "exhibition with ID 4 cannot be updated. Reason: Cannot insert the value NULL into column 'exhibitionTitle', table 'trevorbollenart.dbo.exhibitions'; column does not allow nulls. UPDATE fails. The statement has been terminated."

    All the controls have been filled in (including exhibitionTitle) does anyone have any ideas? I'm guessing I can mix and match GridTemplateColumn and GridBoundColumns?


    Code show below.

    <h2>Manage exhibitions</h2>
            <telerik:RadScriptManager ID="RadScriptManager1" Runat="server">
            </telerik:RadScriptManager>
              
            <p>Items marked with a <span class="radgrid-required">*</span> are required. </p>
            <br />
              
            <br />
            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                <AjaxSettings>
                    <telerik:AjaxSetting AjaxControlID="RadGrid1">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                </AjaxSettings>
            </telerik:RadAjaxManager>
            <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" Skin="Black" runat="server" />
           <telerik:RadGrid ID="RadGrid1" GridLines="None" runat="server" AllowAutomaticDeletes="True"
                AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowPaging="True" PageSize="10"
                AutoGenerateColumns="False" DataSourceID="SqlDataSource1" AllowSorting="True" Skin="Black" ShowStatusBar="True" >
            <PagerStyle Mode="NextPrevAndNumeric" />
            <MasterTableView DataKeyNames="exhibitionID" DataSourceID="SqlDataSource1" CommandItemDisplay="Bottom" Name="exhibitions"
            CommandItemSettings-AddNewRecordText="Add New Exhibition"  >
                    <RowIndicatorColumn>
                        <HeaderStyle Width="20px" />
                    </RowIndicatorColumn>
                    <ExpandCollapseColumn>
                        <HeaderStyle Width="20px" />
                    </ExpandCollapseColumn>
    <CommandItemSettings AddNewRecordText="Add New Exhibition"></CommandItemSettings>
        <Columns>
           <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn" HeaderText="Edit">
                            <ItemStyle CssClass="MyImageButton" />
                        </telerik:GridEditCommandColumn>
              
            <telerik:GridTemplateColumn HeaderText="Exhibition Title" UniqueName="exhibitionTitle" >
                <EditItemTemplate>
                    <asp:TextBox ID="txtExhibitionTitle" runat="server" Width="300" MaxLength="500" Text='<%#Eval("exhibitionTitle")%>' /> <span class="radgrid-required">*</span>
                    <asp:RequiredFieldValidator ID="rfvTitle" runat="server" ErrorMessage="Please enter the exhibition title" ControlToValidate="txtExhibitionTitle" Display="Dynamic" />
                </EditItemTemplate>
                <ItemTemplate>
                <%#Eval("exhibitionTitle")%>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn HeaderText="Gallery Name">
                <EditItemTemplate>
                    <asp:TextBox ID="galleryName" runat="server" Width="300" MaxLength="100" Text='<%#Eval("galleryName")%>'  /> <span class="radgrid-required">*</span>
                    <asp:RequiredFieldValidator ID="rfvGalleryName" runat="server" ErrorMessage="Please enter the gallery name" ControlToValidate="galleryName" Display="Dynamic" />
                </EditItemTemplate>
                <ItemTemplate>
                <%#Eval("galleryName")%>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
             
             <Telerik:GridDateTimeColumn DataField="eventDateTime"
                HeaderText="Event Date & Time" SortExpression="eventDateTime"
                UniqueName="eventDateTime" PickerType="DateTimePicker"  >
            </Telerik:GridDateTimeColumn>
            <telerik:GridTemplateColumn UniqueName="TemplateColumn" HeaderText="Gallery Address">
                <ItemTemplate>
                <%#Eval("galleryAddress")%>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="galleryAddress" runat="server" TextMode="MultiLine" Height="100" Width="300" MaxLength="500" Text='<%#Eval("galleryAddress")%>'  /> <span class="radgrid-required">*</span>
                    <asp:RequiredFieldValidator ID="rfvGalleryAddress" runat="server" ErrorMessage="Please enter the gallery address" ControlToValidate="galleryAddress" Display="Dynamic" />
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn HeaderText="Gallery Website">
                <ItemTemplate>
                <%#Eval("galleryUrl")%>
                </ItemTemplate>
                <EditItemTemplate>
                    http://<;;asp:TextBox ID="galleryUrl" runat="server" Width="300" MaxLength="100" /> i.e. www.trevorbollen.co.uk
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridBoundColumn DataField="galleryTel" HeaderText="Gallery Tel No"
                SortExpression="galleryTel" UniqueName="galleryTel">
            </telerik:GridBoundColumn>
            <telerik:GridTemplateColumn HeaderText="Notes">
                <ItemTemplate>
                <%#Eval("notes")%>
                </ItemTemplate>
                <EditItemTemplate>
                   <asp:TextBox ID="notes" runat="server" TextMode="MultiLine" Width="300" MaxLength="500" />
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
           <telerik:GridButtonColumn ConfirmText="Delete this exhibition?" ConfirmDialogType="RadWindow"
                            ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete"
                            UniqueName="DeleteColumn">
                            <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />
                        </telerik:GridButtonColumn>
              
        </Columns>
      
    <EditFormSettings>
      
    <EditColumn  ButtonType="ImageButton" CancelImageUrl="~/images/btn-cancel.jpg" UpdateImageUrl="~/images/btn-update.jpg" InsertImageUrl="~/images/btn-insert.jpg"  />
    </EditFormSettings>
      
    </MasterTableView>
                <HeaderStyle Font-Bold="False" Font-Italic="False" Font-Overline="False"
                    Font-Strikeout="False" Font-Underline="False" ForeColor="White" Wrap="True" />
            </telerik:RadGrid>
            <br />
            
          
            <br />
            <asp:SqlDataSource ID="SqlDataSource1" runat="server"
                ConnectionString="<%$ ConnectionStrings:trevorbollenartConn %>"
                InsertCommand="AddNewExhibition" InsertCommandType="StoredProcedure"
                SelectCommand="GetAllExhibitions" SelectCommandType="StoredProcedure"
                UpdateCommand="UpdateExhibition" UpdateCommandType="StoredProcedure"
                DeleteCommand="DeleteExhibition" DeleteCommandType="StoredProcedure">
                <DeleteParameters>
                    <asp:Parameter Name="exhibitionID" Type="Int32" />
                </DeleteParameters>
                <UpdateParameters>
                    <asp:Parameter Name="exhibitionID" Type="Int32" />
                    <asp:Parameter Name="exhibitionTitle" Type="String" />
                    <asp:Parameter Name="galleryName" Type="String" />
                    <asp:Parameter Name="eventDateTime" Type="DateTime" />
                    <asp:Parameter Name="galleryAddress" Type="String" />
                    <asp:Parameter Name="galleryURL" Type="String" />
                    <asp:Parameter Name="galleryTel" Type="String" />
                    <asp:Parameter Name="Notes" Type="String" />
                </UpdateParameters>
                <InsertParameters>
                    <asp:Parameter Name="exhibitionTitle" Type="String" />
                    <asp:Parameter Name="galleryName" Type="String" />
                    <asp:Parameter Name="eventDateTime" Type="DateTime" />
                    <asp:Parameter Name="galleryAddress" Type="String" />
                    <asp:Parameter Name="galleryURL" Type="String" />
                    <asp:Parameter Name="galleryTel" Type="String" />
                    <asp:Parameter Name="Notes" Type="String" />
                </InsertParameters>
            </asp:SqlDataSource>
          
        </div>
      
    </asp:Content>
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 31 Mar 2011 Link to this post

    Hello Stevied,

    For two way databinding (using a datasource in which you want to update, insert, etc with declarative databinding), you'll need to use #Bind.

    ASPX:
    <telerik:GridTemplateColumn HeaderText="Exhibition Title" UniqueName="exhibitionTitle" >
       <EditItemTemplate>
          <asp:TextBox ID="txtExhibitionTitle" runat="server" Text='<%#Bind("exhibitionTitle")%>' />
       </EditItemTemplate>
       <ItemTemplate>
          <%#Eval("exhibitionTitle")%>
       </ItemTemplate>
    </telerik:GridTemplateColumn>

    Hope this helps,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. stevied
    stevied avatar
    37 posts
    Member since:
    Apr 2007

    Posted 31 Mar 2011 Link to this post

    Thanks for that Princy, cant believe i missed it!
Back to Top