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

RadComboBox inside RadGrid with inplace editting and allowCustomText

3 Answers 332 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Stephen
Top achievements
Rank 1
Stephen asked on 20 Jul 2011, 07:15 PM
I'm getting the following error when trying to use a radcombobox inside GridTemplateColumn with inplace editing (i.e. using bind to SelectedValue).

Error:
Cannot insert the value NULL into column 'GroupTitle', table 'cms_XXXXX.dbo.cmsContentRelatedGroup'; column does not allow nulls. INSERT fails.

Why would the control pass a null value when the user enters a new "custom text" item?  Any help would be most appreciated.


Below is my RadGrid:

<telerik:RadGrid ID="rgContentRelatedGroup" runat="server" GridLines="None"
                        AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True"
                        AutoGenerateColumns="False" DataSourceID="odsContentRelatedGroup" ShowStatusBar="True">
                        <MasterTableView EditMode="InPlace" DataKeyNames="ContentRelatedGroupID"
                            CellPadding="4" CellSpacing="1" CommandItemDisplay="TopAndBottom">
                            <AlternatingItemStyle CssClass="row-alt" />
                            <ItemStyle CssClass="row" />
                            <CommandItemSettings AddNewRecordImageUrl="~/images/admin/icons/add.gif" AddNewRecordText="Add new quick link category" />
                             <Columns>
                                <telerik:GridBoundColumn DataField="ContentRelatedGroupID" DataType="System.Int32" HeaderText="ContentRelatedGroupID"
                                    ReadOnly="True" Visible="False" SortExpression="ContentRelatedGroupID" UniqueName="ContentRelatedGroupID">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="ContentID" DataType="System.Int32" HeaderText="ContentID"
                                    ReadOnly="True" Visible="False" SortExpression="ContentID" UniqueName="ContentID">
                                </telerik:GridBoundColumn>
                                <telerik:GridEditCommandColumn ButtonType="ImageButton" 
                                        UpdateImageUrl="~/images/admin/icons/update.gif"
                                        EditImageUrl="~/images/admin/icons/edit.gif" 
                                        InsertImageUrl="~/images/admin/icons/add.gif"
                                        CancelImageUrl="~/images/admin/icons/cancel.gif" HeaderText="Action">
                                    <HeaderStyle Width="55px" />
                                    <ItemStyle VerticalAlign="Top" />
                                </telerik:GridEditCommandColumn>
                                <telerik:GridTemplateColumn HeaderText="Category Title" UniqueName="columnRelatedGroup" ItemStyle-VerticalAlign="Top">
                                    <ItemTemplate>
                                        <%# Eval("GroupTitle")%>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <telerik:RadComboBox
                                             ID="rcbGroupTitle" runat="server"
                                             Width="165px" Height="200px"
                                             EmptyMessage="Select a Category"
                                             DataSourceID="odsAllContentRelatedGroup" DataTextField="GroupTitle" DataValueField="GroupTitle"
                                             AllowCustomText="true" MarkFirstMatch="true" SelectedValue='<%# Bind("GroupTitle") %>' AppendDataBoundItems="true">
                                        </telerik:RadComboBox>
                                        <asp:RequiredFieldValidator runat="server" id="reqGroupTitle" ControlToValidate="rcbGroupTitle" ErrorMessage="Category Title" display="Dynamic"><br />Category Title is a required field</asp:RequiredFieldValidator>                        
                                    </EditItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn HeaderText="Sort Order" UniqueName="columnSortOrder" ItemStyle-VerticalAlign="Top">
                                    <ItemTemplate>
                                        <%# Eval("Rank")%>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <asp:TextBox ID="tbGroupSortOrder" runat="server" Width="50" Text='<%# Bind("Rank") %>'></asp:TextBox>
                                        <asp:CompareValidator ID="cvGroupSortOrder" runat="server" Operator="DataTypeCheck" Type="Integer" ControlToValidate="tbGroupSortOrder" ErrorMessage="Sort Order" Display="Dynamic"><br />Sort Order must be a number</asp:CompareValidator>
                                        <asp:RequiredFieldValidator runat="server" id="reqGroupSortOrder" ControlToValidate="tbGroupSortOrder" ErrorMessage="Sort Order" display="Dynamic"><br />Sort Order is a required field</asp:RequiredFieldValidator>
                                    </EditItemTemplate>
                                </telerik:GridTemplateColumn>                          
                                <telerik:GridTemplateColumn HeaderText="Last Updated" UniqueName="columnLastUpdated" ItemStyle-VerticalAlign="Top">
                                    <ItemTemplate>
                                        <%# Eval("DateUpdated")%>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                    </EditItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn HeaderText="Updated By" UniqueName="columnUpdatedBy" ItemStyle-VerticalAlign="Top">
                                    <ItemTemplate>
                                        <%# Eval("UpdatedBy")%>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                    </EditItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridButtonColumn ConfirmText="Delete this category and all links associated with it?" HeaderText="Delete" ButtonType="ImageButton" ImageUrl="~/images/admin/icons/delete.gif" CommandName="Delete" Text="Delete" UniqueName="DeleteColumn" ItemStyle-VerticalAlign="Top">
                                    <HeaderStyle Width="20px" />
                                    <ItemStyle HorizontalAlign="Center" />
                                </telerik:GridButtonColumn>      
                            </Columns>
                            <EditFormSettings ColumnNumber="2">
                                <FormTableItemStyle Wrap="False"></FormTableItemStyle>
                                <FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle>
                                <FormMainTableStyle GridLines="Horizontal" CellSpacing="0" CellPadding="3" BackColor="White"
                                    Width="100%" />
                                <FormTableStyle CellSpacing="0" CellPadding="2" CssClass="module" Height="110px"
                                    BackColor="White" />
                                <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>
                                <EditColumn ButtonType="ImageButton" UpdateImageUrl="~/images/admin/icons/update.gif"
                                    EditImageUrl="~/images/admin/icons/edit.gif" InsertImageUrl="~/images/admin/icons/add.gif"
                                    CancelImageUrl="~/images/admin/icons/cancel.gif" InsertText="Insert record" UpdateText="Update record"
                                    UniqueName="ContentGroupEditCommandColumn" CancelText="Cancel edit">
                                </EditColumn>
                                <FormTableButtonRowStyle HorizontalAlign="Right"></FormTableButtonRowStyle>
                            </EditFormSettings>
                            <ExpandCollapseColumn Visible="False">
                                <HeaderStyle Width="19px" />
                            </ExpandCollapseColumn>
                            <RowIndicatorColumn Visible="False">
                                <HeaderStyle Width="20px" />
                            </RowIndicatorColumn>
                        </MasterTableView>
                    </telerik:RadGrid>

And here are the two datasources:

<asp:ObjectDataSource ID="odsAllContentRelatedGroup" runat="server" SelectMethod="GetAllContentRelatedGroup" 
                        TypeName="dsCmsContentTableAdapters.cmsContentRelatedGroupTableAdapter">
                    </asp:ObjectDataSource>
                    
                    <asp:ObjectDataSource ID="odsContentRelatedGroup" runat="server" DeleteMethod="DeleteContentRelatedGroup"
                        InsertMethod="InsertContentRelatedGroup" SelectMethod="GetContentRelatedGroupByContentID" TypeName="dsCmsContentTableAdapters.cmsContentRelatedGroupTableAdapter"
                        UpdateMethod="UpdateContentRelatedGroup">
                        <SelectParameters>
                            <asp:SessionParameter Name="ContentID" SessionField="ContentID" Type="Int32" />
                        </SelectParameters>
                        <InsertParameters>
                            <asp:SessionParameter Name="ContentID" SessionField="ContentID" Type="Int32" />
                            <asp:Parameter Name="GroupTitle" Type="String" />
                            <asp:Parameter Name="Rank" Type="Int32" />
                            <asp:SessionParameter Name="CreatedBy" SessionField="Username" Type="String" />
                            <asp:Parameter Direction="InputOutput" Name="NewContentRelatedGroupID" Type="Object" />
                        </InsertParameters>
                        <DeleteParameters>
                            <asp:Parameter Name="ContentRelatedGroupID" Type="Int32" />
                        </DeleteParameters>
                    </asp:ObjectDataSource>

And finally the stack:

System.Reflection.TargetInvocationException was unhandled by user code
  Message=Exception has been thrown by the target of an invocation.
  Source=mscorlib
  StackTrace:
       at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
       at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
       at System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object& instance)
       at System.Web.UI.WebControls.ObjectDataSourceView.ExecuteInsert(IDictionary values)
       at System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback)
       at Telerik.Web.UI.GridTableView.PerformInsert(GridEditableItem editedItem, Boolean suppressRebind)
       at Telerik.Web.UI.GridTableView.PerformInsert(GridEditableItem editedItem)
       at Telerik.Web.UI.GridTableView.PerformInsert()
       at Telerik.Web.UI.GridCommandEventArgs.ExecuteCommand(Object source)
       at Telerik.Web.UI.RadGrid.OnBubbleEvent(Object source, EventArgs e)
       at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
       at Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e)
       at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
       at Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e)
       at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
       at System.Web.UI.WebControls.ImageButton.OnCommand(CommandEventArgs e)
       at System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at admin_content_edit.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) in e:\work\wwwroot\cms.wageworks\admin\content-edit.aspx.cs:line 359
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: System.Data.SqlClient.SqlException
       Message=Cannot insert the value NULL into column 'GroupTitle', table 'cms_XXXXXX.dbo.cmsContentRelatedGroup'; column does not allow nulls. INSERT fails.
The statement has been terminated.
       Source=.Net SqlClient Data Provider
       ErrorCode=-2146232060
       Class=16
       LineNumber=17
       Number=515
       Procedure=usp_cmsContentRelatedGroupINSERT
       Server=XXXXXXXXXX
       State=2
       StackTrace:
            at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
            at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
            at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
            at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
            at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
            at System.Data.SqlClient.SqlDataReader.get_MetaData()
            at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
            at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
            at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
            at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
            at System.Data.SqlClient.SqlCommand.ExecuteScalar()
            at dsCmsContentTableAdapters.cmsContentRelatedGroupTableAdapter.InsertContentRelatedGroup(Nullable`1 ContentID, String GroupTitle, Nullable`1 Rank, String CreatedBy, Nullable`1& NewContentRelatedGroupID) in c:\Users\mrhigh\AppData\Local\Temp\Temporary ASP.NET Files\root\98f11740\866a4947\App_Code.6d7gpkps.5.cs:line 16649
       InnerException: 

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 21 Jul 2011, 07:06 AM
Hello Stephen,

I tried the same scenario and it worked as expected in my end. Here is the sample code that I tried.

aspx:
<telerik:GridTemplateColumn UniqueName="TemplateCol" HeaderText="Test">
  <EditItemTemplate>
      <telerik:RadComboBox ID="RadCombobox1" runat="server" DataSourceID="SqlDataSource1"
    DataTextField="GroupTitle" DataValueField="GroupTitle" AllowCustomText="true" MarkFirstMatch="true"
            SelectedValue='<%# Bind("GroupTitle") %> '>
      </telerik:RadComboBox>
   </EditItemTemplate>
</telerik:GridTemplateColumn>

Also check the following help documentation which explains more on this.
RadComboBox in RadGrid.

Thanks,
Shinu.
0
Vikram
Top achievements
Rank 1
answered on 15 Oct 2012, 10:20 PM
Can RadComboBox be used in edit mode for dynamically added columns ?
0
Shinu
Top achievements
Rank 2
answered on 16 Oct 2012, 06:09 AM
Hi,

You can create TemplateColumns programmatically. Here is the sample code.
C#:
protected void Page_Init(object sender, EventArgs e)
{ //define the radgrid here
 NewTemplateColumn templateColumn = new NewTemplateColumn();
 templateColumn.EditItemTemplate = new TemplateColumn();
 grid.MasterTableView.Columns.Add(templateColumn);
}
public class RadGridEditTemplate : ITemplate
{
  public void InstantiateIn(System.Web.UI.Control container)
  {
     RadComboBox combo = new RadComboBox();
     combo.DataTextField = "Id";
     combo.DataValueField = "Id";
     combo.DataSourceID = "SqlDataSource1";
     container.Controls.Add(combo);
  }
}
public partial class NewTemplateColumn : GridTemplateColumn
{
}

Thanks,
Shinu.
Tags
ComboBox
Asked by
Stephen
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Vikram
Top achievements
Rank 1
Share this question
or