AutoCompleteBox does not bind ID in EDIT mode

2 posts, 0 answers
  1. Luis
    Luis avatar
    1 posts
    Member since:
    Oct 2014

    Posted 15 Jan 2015 Link to this post

    I follow several samples and nothing seems wrong with my code, but I still receiving a NULL value error when I try to insert a value. The product_id parameter is not binded and pass onto the INSERT SQL statement. Here is my code

    ASP.NET
    <
    telerik:RadGrid ID="RadGrid1" runat="server"
                AllowAutomaticDeletes="True"
                AllowAutomaticInserts="True"
                AllowAutomaticUpdates="True"
                AllowFilteringByColumn="True"
                AllowPaging="True"
                AllowSorting="True"
                DataSourceID="SqlDataSource1"
                OnItemDataBound="RadGrid1_ItemDataBound"
                EnableLinqExpressions ="false">
     
                <MasterTableView AutoGenerateColumns="False" DataSourceID="SqlDataSource1" CommandItemDisplay="Top" DataKeyNames="product_name">
         
                    <EditFormSettings EditFormType="Template">
                                <FormTemplate>
                        
                                                <telerik:RadAutoCompleteBox ID="radAutoCompleteBox1" runat="server"
                                                    DataSourceID="SqlDataSource6"
                                                    DataTextField="product_name"
                                                    DataValueField="product_id"
                                                    InputType="Text"
                                                    Delimiter=" "
                                                    SelectionMode="Single"
                                                    Width="300"
                                                    EmptyMessage="Type product name...">
                                                </telerik:RadAutoCompleteBox>
      
                                      
                                </FormTemplate>
                            </EditFormSettings>
                </MasterTableView>
            </telerik:RadGrid>
    VB

    Protected
    Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs)
            If e.Item.IsInEditMode Then
                Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem)
                If Not (TypeOf e.Item Is IGridInsertItem) Then
                    Dim radAutoCompleteBox1 As RadAutoCompleteBox = DirectCast(item.FindControl("radAutoCompleteBox1"), RadAutoCompleteBox)
                    radAutoCompleteBox1.Entries.Add(New AutoCompleteBoxEntry(item("product_name").Text, item("product_name").Text))
                End If
            End If
        End Sub
  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 20 Jan 2015 Link to this post

    Hello,

    I would suggest using the <asp:SessionParameter ...> to store the selected item id. You can set it as shown below:
    //markup code
    <InsertParameters>
                <asp:Parameter Name="ProductName" Type="String" />
                <asp:SessionParameter SessionField="SupplierID" Name="SupplierID" Type="Int32" />
                <asp:Parameter Name="CategoryID" Type="Int32" />
    </InsertParameters>

    When you select a new item in the RadAutoCompleteBox you can set it in the Session. Please use this demo as reference.

    Regards,
    Boyan Dimitrov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top