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

RadautoComplete in a grid

6 Answers 54 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
jack
Top achievements
Rank 1
jack asked on 26 Aug 2014, 07:52 PM
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

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 27 Aug 2014, 03:27 AM
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.
0
jack
Top achievements
Rank 1
answered on 27 Aug 2014, 01:11 PM
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()

0
jack
Top achievements
Rank 1
answered on 27 Aug 2014, 01:14 PM
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()


0
jack
Top achievements
Rank 1
answered on 27 Aug 2014, 09:27 PM
I was able to fix this problem today. will post code later
0
Shinu
Top achievements
Rank 1
answered on 28 Aug 2014, 03:52 AM
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.
0
jack
Top achievements
Rank 1
answered on 28 Aug 2014, 01:05 PM
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



Tags
AutoCompleteBox
Asked by
jack
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
jack
Top achievements
Rank 1
Share this question
or