RadautoComplete in a grid

7 posts, 0 answers
  1. jack
    jack avatar
    5 posts
    Member since:
    Oct 2010

    Posted 26 Aug 2014 Link to this post

    Can RadautoComplete be used in the EditItemTemplate of a radgrid? I am trying to use it there but having a problem seeing the data


    Thank you

    Jack
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 26 Aug 2014 in reply to jack Link to this post

    Hi Jack,

    As far as I know there is no such issue to use RadAutoCompleteBox in RadGrid EditItemTemplate. Please have a look into the sample code snippet which works fine at my end. Please provide your code if it doesn't work

    ASPX:
    <telerik:RadGrid ID="rgrdOrders" runat="server" DataSourceID="sqldsOrders" AutoGenerateColumns="false"
        AutoGenerateEditColumn="true">
        <MasterTableView>
            <Columns>
                <telerik:GridBoundColumn DataField="OrderID" HeaderText="OrderID" UniqueName="OrderID">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="CustomerID" HeaderText="CustomerID" UniqueName="CustomerID">
                </telerik:GridBoundColumn>
                <telerik:GridTemplateColumn HeaderText="ShipName">
                    <EditItemTemplate>
                        <telerik:RadAutoCompleteBox ID="rautocompleteOrders" runat="server" DataSourceID="sqldsOrders" DataTextField="ShipName" DataValueField="OrderID">
                        </telerik:RadAutoCompleteBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. jack
    jack avatar
    5 posts
    Member since:
    Oct 2010

    Posted 27 Aug 2014 in reply to Shinu Link to this post

    this is how I am trying to make it work
     *******This radAutocomplete works outside of the grid . because I set the datasource in the pageload*******
     
     <telerik:RadAutoCompleteBox ID="RadAutoCompleteBox1" AllowCustomEntry="true"  OnEntryAdded="RadAutoCompleteBox1_EntryAdded" InputType="Token" runat="server"></telerik:RadAutoCompleteBox>

      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

            Dim paramColl As List(Of OracleParameter) = New List(Of OracleParameter)()
            paramColl.Add(New OracleParameter("o_RECORDSET", OracleDbType.RefCursor, ParameterDirection.Output))
            Dim dt As DataTable
            dt = OracleHelper.RetrieveDataTable("GET_MESSAGE_ELEMENT", paramColl)

            RadAutoCompleteBox1.DataSource = dt
            RadAutoCompleteBox1.DataTextField = "name"
            RadAutoCompleteBox1.DataValueField = "id"
        End Sub
     
     *************
     I tried to do something similar for this autocomplete but I get a error saying datasource or datasourceId is not set/
     
                <telerik:RadGrid ID="rgvPrimitiveAssoctoMessage" runat="server" GridLines="None" AutoGenerateColumns="False" MasterTableView-NoMasterRecordsText="No Records To Display" CellSpacing="0">
                    <MasterTableView DataKeyNames="ielm_Id" CommandItemDisplay="Top" NoDetailRecordsText="No Records To Display" EditMode="InPlace">                
                   
                        <Columns>
                           <telerik:GridEditCommandColumn  ButtonType="ImageButton" UniqueName="EditCommandColumn"  />

                            <telerik:GridBoundColumn DataField="ielm_Id" HeaderText="Elementid" UniqueName="Elementid" Display="False"  Visible="False" Resizable="False"></telerik:GridBoundColumn>

                            <telerik:GridTemplateColumn UniqueName="Elem_nm" HeaderText="Element Name"   >
                                <ItemTemplate>
                                     <asp:LinkButton ID="lblMessageElement" CommandName="EDIT" runat="server" Text='<%#Container.DataItem("ielm_nm")%>'  />                                                           
                                </ItemTemplate>
                                <EditItemTemplate>
                                   <%-- <telerik:RadComboBox runat="server" ID="rcbelement" DataTextField="ielm_nm" DataValueField="ielm_id" DropDownAutoWidth="Enabled"></telerik:RadComboBox>--%>
                                    <telerik:RadAutoCompleteBox ID="RadAutoCompleteBox2" AllowCustomEntry="true"  InputType="Token" runat="server"></telerik:RadAutoCompleteBox>
                                </EditItemTemplate>
                            </telerik:GridTemplateColumn>

    **********************************
     Protected Sub RgvMessage_ItemDataBound(sender As Object, e As GridItemEventArgs) Handles rgvMessage.ItemDataBound
            Dim dt As DataTable
    Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem)

    Dim paramColl As List(Of OracleParameter) = New List(Of OracleParameter)()
                    paramColl.Add(New OracleParameter("o_RECORDSET", OracleDbType.RefCursor, ParameterDirection.Output))

                    dt = OracleHelper.RetrieveDataTable("GET_MESSAGE_ELEMENT", paramColl)

                    Dim msgElement As RadAutoCompleteBox = DirectCast(item.FindControl("RadAutoCompleteBox2"), RadAutoCompleteBox)

                    msgElement.DataSource = dt
                    msgElement.DataTextField = "Name"
                    msgElement.DataValueField = "Id"

                    msgElement.DataBind()

  5. jack
    jack avatar
    5 posts
    Member since:
    Oct 2010

    Posted 27 Aug 2014 in reply to Shinu Link to this post

    Thanks, think my problem is with the "DataSourceID=" Because I am using oracle and  we call it a different way. Here is my code snippet.


     *******This radAutocomplete works outside of the grid . because I set the datasource in the pageload*******
     
     <telerik:RadAutoCompleteBox ID="RadAutoCompleteBox1" AllowCustomEntry="true"  OnEntryAdded="RadAutoCompleteBox1_EntryAdded" InputType="Token" runat="server"></telerik:RadAutoCompleteBox>

      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

            Dim paramColl As List(Of OracleParameter) = New List(Of OracleParameter)()
            paramColl.Add(New OracleParameter("o_RECORDSET", OracleDbType.RefCursor, ParameterDirection.Output))
            Dim dt As DataTable
            dt = OracleHelper.RetrieveDataTable("GET_MESSAGE_ELEMENT", paramColl)

            RadAutoCompleteBox1.DataSource = dt
            RadAutoCompleteBox1.DataTextField = "name"
            RadAutoCompleteBox1.DataValueField = "id"
        End Sub
     
     *************
     I tried to do something similar for this autocomplete but I get a error saying datasource or datasourceId is not set/
     
                <telerik:RadGrid ID="rgvPrimitiveAssoctoMessage" runat="server" GridLines="None" AutoGenerateColumns="False" MasterTableView-NoMasterRecordsText="No Records To Display" CellSpacing="0">
                    <MasterTableView DataKeyNames="ielm_Id" CommandItemDisplay="Top" NoDetailRecordsText="No Records To Display" EditMode="InPlace">                
                   
                        <Columns>
                           <telerik:GridEditCommandColumn  ButtonType="ImageButton" UniqueName="EditCommandColumn"  />

                            <telerik:GridBoundColumn DataField="ielm_Id" HeaderText="Elementid" UniqueName="Elementid" Display="False"  Visible="False" Resizable="False"></telerik:GridBoundColumn>

                            <telerik:GridTemplateColumn UniqueName="Elem_nm" HeaderText="Element Name"   >
                                <ItemTemplate>
                                     <asp:LinkButton ID="lblMessageElement" CommandName="EDIT" runat="server" Text='<%#Container.DataItem("ielm_nm")%>'  />                                                           
                                </ItemTemplate>
                                <EditItemTemplate>
                                   <%-- <telerik:RadComboBox runat="server" ID="rcbelement" DataTextField="ielm_nm" DataValueField="ielm_id" DropDownAutoWidth="Enabled"></telerik:RadComboBox>--%>
                                    <telerik:RadAutoCompleteBox ID="RadAutoCompleteBox2" AllowCustomEntry="true"  InputType="Token" runat="server"></telerik:RadAutoCompleteBox>
                                </EditItemTemplate>
                            </telerik:GridTemplateColumn>

    **********************************
     Protected Sub RgvMessage_ItemDataBound(sender As Object, e As GridItemEventArgs) Handles rgvMessage.ItemDataBound
            Dim dt As DataTable
    Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem)

    Dim paramColl As List(Of OracleParameter) = New List(Of OracleParameter)()
                    paramColl.Add(New OracleParameter("o_RECORDSET", OracleDbType.RefCursor, ParameterDirection.Output))

                    dt = OracleHelper.RetrieveDataTable("GET_MESSAGE_ELEMENT", paramColl)

                    Dim msgElement As RadAutoCompleteBox = DirectCast(item.FindControl("RadAutoCompleteBox2"), RadAutoCompleteBox)

                    msgElement.DataSource = dt
                    msgElement.DataTextField = "Name"
                    msgElement.DataValueField = "Id"

                    msgElement.DataBind()


  6. jack
    jack avatar
    5 posts
    Member since:
    Oct 2010

    Posted 27 Aug 2014 in reply to jack Link to this post

    I was able to fix this problem today. will post code later
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 27 Aug 2014 in reply to jack Link to this post

    Hi Jack,

    Try to bind the RadAutoCompleteBox in the ItemCreated event of RadGrid which works fine at my end.

    C#:
    protected void ThatGrid_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
            var item = e.Item as GridEditFormItem;
            RadAutoCompleteBox autocompletebox = (RadAutoCompleteBox)item.FindControl("RadAutoCompleteBoxValue");
            autocompletebox.DataSourceID = "SqlDataSource1";
            autocompletebox.DataBind();
        }
    }

    Thanks,
    Shinu.
  8. jack
    jack avatar
    5 posts
    Member since:
    Oct 2010

    Posted 28 Aug 2014 Link to this post

    Yes I finally got it to work and here is my code on what I did .

    How I fixed the problem of AutoComplete box not working in RadGrid Edititem.
    1) Added postback to True
    2) DataTextField="Name" & DataValueField="id"
    3) OnEntryAdded I added this toi get the id value back from the autocomplete

    ****************************************************************************

     <Columns>
             <telerik:GridEditCommandColumn  ButtonType="ImageButton" UniqueName="EditCommandColumn"  />

             <telerik:GridBoundColumn DataField="ielm_Id" HeaderText="Elementid" UniqueName="Elementid" Display="False"  Visible="False" Resizable="False"></telerik:GridBoundColumn>

              <telerik:GridTemplateColumn UniqueName="Elem_nm" HeaderText="Element Name"   >
               <ItemTemplate>
                     <asp:LinkButton ID="lblMessageElement" CommandName="EDIT" runat="server" Text='<%#Container.DataItem("ielm_nm")%>'  />   
                </ItemTemplate>
                <EditItemTemplate>
    <%-- <telerik:RadComboBox runat="server" ID="rcbelement" AllowCustomText="true"  DataTextField="ielm_nm" DataValueField="ielm_id" DropDownAutoWidth="Enabled" AutoPostBack="True" MinFilterLength="3"></telerik:RadComboBox>--%>

                        <telerik:RadAutoCompleteBox ID="RadAutoCompleteBox2"  OnEntryAdded="RadAutoCompleteBox2_EntryAdded" AutoPostBack="true" DataTextField="Name" DataValueField="id" AllowCustomEntry="true" InputType="Token"  runat="server" MinFilterLength="3"></telerik:RadAutoCompleteBox>
                                
                  </EditItemTemplate>
                  </telerik:GridTemplateColumn>


    *************** Page load  ********************************

    Using page load to populate the session datatable 

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

            If Not IsPostBack Then
                Dim paramColl As List(Of OracleParameter) = New List(Of OracleParameter)()
                paramColl.Add(New OracleParameter("o_RECORDSET", OracleDbType.RefCursor, ParameterDirection.Output))

                Session("dt") = OracleHelper.RetrieveDataTable("GET_MESSAGE_ELEMENT", paramColl)

           End If
    end sub 


    *************** Item Created  ********************************


    I had to find a sub that would allow me to set the autocomplete datasource before the error "datasource not set"

    Protected Sub rgvPrimitiveAssoctoMessage_ItemCreated(sender As Object, e As GridItemEventArgs) Handles rgvPrimitiveAssoctoMessage.ItemCreated

     If TypeOf e.Item Is IGridInsertItem Then

                Dim item = TryCast(e.Item, GridEditableItem)

                Dim AutoCompleteBox As RadAutoCompleteBox = DirectCast(item.FindControl("RadAutoCompleteBox2"), RadAutoCompleteBox)

                AutoCompleteBox.DataSource = Session("dt")
                AutoCompleteBox.DataTextField = "Name"
                AutoCompleteBox.DataValueField = "Id"
                AutoCompleteBox.DataBind()

            End If

    getting value from Autocomplete


    Protected Sub RadAutoCompleteBox2_EntryAdded(sender As Object, e As AutoCompleteEntryEventArgs)
            Session("label1") = e.Entry.Value

        End Sub



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