I am trying to replace a textbox in a grid edit form with an autocomplete. The autocomplete is correctly suggesting the possible entries but does not bind the selected value to the db on insert.
So far this is the markup I am using where you see the old text box and the autocomplete.
How can I bind the selected value to the db?
So far this is the markup I am using where you see the old text box and the autocomplete.
<%-- <
telerik:RadTextBox
ID
=
"ProjManag"
TabIndex
=
"2"
runat
=
"server"
Width
=
"200px"
onkeypress
=
"return this.value.length<=25"
Text='<%# Bind( "ProjManag" ) %>'>
</
telerik:RadTextBox
>--%>
<
telerik:RadAutoCompleteBox
ID
=
"ProjManag"
runat
=
"server"
AllowCustomEntry
=
"True"
Culture
=
"it-IT"
DataSourceID
=
"SqlDataSource1"
DataTextField
=
"ProjManag"
DataValueField
=
"ProjManag"
Filter
=
"StartsWith"
InputType
=
"Text"
Skin
=
"Outlook"
>
</
telerik:RadAutoCompleteBox
>
How can I bind the selected value to the db?
4 Answers, 1 is accepted
0

Felice
Top achievements
Rank 1
answered on 29 Jun 2014, 05:14 PM
Unfortunately I cannot edit my original post so I add some info here:
I was able to make it working and get the autocomplete functional in this way:
But I still have two issues that I am not able to solve:
1) when I open again the record for modification the autocompletebox is empty. It is not showing the value that is in the database. I understand this is the normal behavior of such control because the user has to start typing to see values in there. But I need to use it that once the record is inserted then the value in the text box should show the value bind in the DB.
Is there a way to achieve a scenario where initially the autocomplete is empty, then the user start typing and select a value, once the value is posted to the DB than next time the edit form gets opened for modification the value in the DB is shown in the autocomplete?
2) How can I avoid the char ";" that is always placed at the end of the selected value and posted to the DB?
I was able to make it working and get the autocomplete functional in this way:
<
telerik:RadAutoCompleteBox
ID
=
"ProjManag"
TabIndex
=
"2"
runat
=
"server"
AllowCustomEntry
=
"True"
Culture
=
"it-IT"
DataSourceID
=
"SqlDataSource1"
DataTextField
=
"ProjManag"
DataValueField
=
"ProjManag"
Filter
=
"StartsWith"
InputType
=
"Text"
SelectionMode
=
"Single"
Skin
=
"Outlook"
Text='<%# Bind( "ProjManag" ) %>'> </
telerik:RadAutoCompleteBox
>
But I still have two issues that I am not able to solve:
1) when I open again the record for modification the autocompletebox is empty. It is not showing the value that is in the database. I understand this is the normal behavior of such control because the user has to start typing to see values in there. But I need to use it that once the record is inserted then the value in the text box should show the value bind in the DB.
Is there a way to achieve a scenario where initially the autocomplete is empty, then the user start typing and select a value, once the value is posted to the DB than next time the edit form gets opened for modification the value in the DB is shown in the autocomplete?
2) How can I avoid the char ";" that is always placed at the end of the selected value and posted to the DB?
0

Shinu
Top achievements
Rank 2
answered on 30 Jun 2014, 07:18 AM
Hi Felice,
In order to set an initially selected Entry in RadAutoCompleteBox you need to add a new entry to control Entriescollection. Set the column as DataKeyNames="ProjManag" and to avoid ";" set Delimiter=" ".
C#:
Thanks,
Shinu
In order to set an initially selected Entry in RadAutoCompleteBox you need to add a new entry to control Entriescollection. Set the column as DataKeyNames="ProjManag" and to avoid ";" set Delimiter=" ".
C#:
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridEditableItem && e.Item.IsInEditMode && !e.Item.OwnerTableView.IsItemInserted)
{
GridEditableItem editItem = (GridEditableItem)e.Item;
RadAutoCompleteBox rProjMang = (RadAutoCompleteBox)editItem.FindControl(
"ProjManag"
);
rProjMang.Entries.Add(
new
AutoCompleteBoxEntry(editItem.GetDataKeyValue(
"ProjManag"
).ToString(), editItem.GetDataKeyValue(
"ProjManag"
).ToString()));
}
}
Thanks,
Shinu
0

Felice
Top achievements
Rank 1
answered on 30 Jun 2014, 03:24 PM
Dear Shinu,
thanks for your support. The situation is improved but still I have something not working properly:
This is my actual code:
The SQLdatasource I am using is the same used by the grid.
I have added "ProjManag" field in the datakeynames:
The problems I am experiencing are the following:
-Now the name in the field "ProjManag" appears when I open the record for modifications. If I delete the value and start typing a new value the autocomplete shows the possibilities. However if I choose a different one than the original one I deleted, it is not saved to the DB.
-If I add Delimiter=" " or Delimiter="", the autocomplete does not work anymore.
Any hint? Did you picked up that in the original post I mentioned that this autocomplete is in a template edit form?
thanks for your support. The situation is improved but still I have something not working properly:
This is my actual code:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditableItem && e.Item.IsInEditMode &&!e.Item.OwnerTableView.IsItemInserted)
{
GridEditableItem editItem = (GridEditableItem)e.Item;
RadAutoCompleteBox rProjMang = (RadAutoCompleteBox)editItem.FindControl("ProjManag");
rProjMang.Entries.Add(new AutoCompleteBoxEntry(editItem.GetDataKeyValue("ProjManag").ToString(), editItem.GetDataKeyValue("ProjManag").ToString()));
}
}
<
telerik:RadAutoCompleteBox
ID
=
"ProjManag"
TabIndex
=
"2"
runat
=
"server"
AllowCustomEntry
=
"True"
Culture
=
"it-IT"
DataSourceID
=
"SqlDataSource1"
DataTextField
=
"ProjManag"
DataValueField
=
"ProjManag"
Filter
=
"StartsWith"
InputType
=
"Text"
SelectionMode
=
"Single"
Skin
=
"Outlook"
Text='<%# Bind( "ProjManag")%>'>
</
telerik:RadAutoCompleteBox
>
The SQLdatasource I am using is the same used by the grid.
I have added "ProjManag" field in the datakeynames:
<
MasterTableView
CommandItemDisplay
=
"Top"
DataKeyNames
=
"Id, ProjManag"
DataSourceID
=
"SqlDataSource1"
>
The problems I am experiencing are the following:
-Now the name in the field "ProjManag" appears when I open the record for modifications. If I delete the value and start typing a new value the autocomplete shows the possibilities. However if I choose a different one than the original one I deleted, it is not saved to the DB.
-If I add Delimiter=" " or Delimiter="", the autocomplete does not work anymore.
Any hint? Did you picked up that in the original post I mentioned that this autocomplete is in a template edit form?
0
Accepted

Shinu
Top achievements
Rank 2
answered on 02 Jul 2014, 04:46 AM
Hi Felice,
Please try the sample code snippet given below, the update works fine at my end.
ASPX:
C#:
Thanks,
Shinu
Please try the sample code snippet given below, the update works fine at my end.
ASPX:
<
telerik:RadAjaxManager
ID
=
"RadAjaxMaanger1"
runat
=
"server"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadGrid1"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGrid1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
DataSourceID
=
"SqlDataSource1"
AllowAutomaticInserts
=
"True"
AllowAutomaticUpdates
=
"True"
AllowAutomaticDeletes
=
"True"
AllowPaging
=
"True"
OnItemDataBound
=
"RadGrid1_ItemDataBound"
>
<
MasterTableView
CommandItemDisplay
=
"Top"
DataKeyNames
=
"OrderID"
AutoGenerateColumns
=
"False"
>
<
Columns
>
<
telerik:GridEditCommandColumn
>
</
telerik:GridEditCommandColumn
>
<
telerik:GridButtonColumn
UniqueName
=
"DeleteButton"
Text
=
"Delete"
CommandName
=
"Delete"
>
</
telerik:GridButtonColumn
>
<
telerik:GridBoundColumn
DataField
=
"OrderID"
HeaderText
=
"OrderID"
ReadOnly
=
"true"
UniqueName
=
"OrderID"
Display
=
"True"
/>
<
telerik:GridBoundColumn
DataField
=
"CustomerID"
HeaderText
=
"CustomerID"
UniqueName
=
"CustomerID"
/>
<
telerik:GridBoundColumn
DataField
=
"EmployeeID"
HeaderText
=
"EmployeeID"
UniqueName
=
"EmployeeID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"ShipName"
HeaderText
=
"ShipName"
UniqueName
=
"ShipName"
/>
</
Columns
>
<
EditFormSettings
EditFormType
=
"Template"
>
<
FormTemplate
>
CustomerID:
<
asp:TextBox
ID
=
"TextBox2"
Text='<%# Bind("CustomerID") %>' runat="server">
</
asp:TextBox
>
EmployeeID:
<
asp:TextBox
ID
=
"TextBox1"
Text='<%# Bind("EmployeeID") %>' runat="server">
</
asp:TextBox
>
ShipName:
<
telerik:RadAutoCompleteBox
ID
=
"racbShipName"
runat
=
"server"
DataSourceID
=
"SqlDataSource1"
Delimiter
=
" "
Filter
=
"StartsWith"
InputType
=
"Text"
SelectionMode
=
"Single"
DataTextField
=
"ShipName"
DataValueField
=
"ShipName"
AllowCustomEntry
=
"True"
Text='<%# Bind("ShipName")%>'>
</
telerik:RadAutoCompleteBox
>
<
asp:Button
ID
=
"btnUpdate"
Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
</
asp:Button
>
<
asp:Button
ID
=
"btnCancel"
Text
=
"Cancel"
runat
=
"server"
CausesValidation
=
"False"
CommandName
=
"Cancel"
></
asp:Button
>
</
FormTemplate
>
</
EditFormSettings
>
</
MasterTableView
>
</
telerik:RadGrid
>
<
asp:SqlDataSource
ID
=
"SqlDataSource1"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:Northwind_newConnectionString3 %>"
SelectCommand="SELECT [OrderID], [CustomerID], [EmployeeID], [ShipName] FROM [Orders]"
DeleteCommand="DELETE FROM [Orders] WHERE [OrderID] = @OrderID" InsertCommand="INSERT INTO [Orders] ([CustomerID], [EmployeeID], [ShipName]) VALUES (@CustomerID, @EmployeeID, @ShipName)"
UpdateCommand="UPDATE [Orders] SET [CustomerID] = @CustomerID, [EmployeeID] = @EmployeeID, [ShipName] = @ShipName WHERE [OrderID] = @OrderID">
<
DeleteParameters
>
<
asp:Parameter
Name
=
"OrderID"
Type
=
"Int32"
/>
</
DeleteParameters
>
<
InsertParameters
>
<
asp:Parameter
Name
=
"CustomerID"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"EmployeeID"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"ShipName"
Type
=
"String"
/>
</
InsertParameters
>
<
UpdateParameters
>
<
asp:Parameter
Name
=
"CustomerID"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"EmployeeID"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"ShipName"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"OrderID"
Type
=
"Int32"
/>
</
UpdateParameters
>
</
asp:SqlDataSource
>
C#:
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridEditableItem && e.Item.IsInEditMode && !e.Item.OwnerTableView.IsItemInserted)
{
GridEditableItem editItem = (GridEditableItem)e.Item;
RadAutoCompleteBox racbShipName = (RadAutoCompleteBox)editItem.FindControl(
"racbShipName"
);
racbShipName.Entries.Add(
new
AutoCompleteBoxEntry(editItem[
"ShipName"
].Text, editItem[
"ShipName"
].Text));
}
}
Thanks,
Shinu