Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

how to use autoComplete Extender in a formview

$
0
0

Hi all,

I have a autocomplete extender in a web form which gets data from a weg service

the data comes back as a text/value pair, I have the text for the autocomp[lete extender and the value for the DB id

my question is how do I bind the value ID in my formView?

im thinking i should set a hidden labels text field to the value ID and bind to that but im not very proficient at javascript (as i belive it must be client side)

here is the said part of the aspx

<

asp:FormViewID="FormView1"runat="server"DataKeyNames="gig_id"
DataSourceID="Diary_SqlDataSource1"
DefaultMode="Insert">
<InsertItemTemplate>
<asp:LabelID="dateLabel"runat="server"Text="No date selected"></asp:Label>
<asp:TextBoxID="dateTextBox"runat="server"Text='<%# Bind("date") %>'Visible="false"/>&nbsp;
<br/>
<asp:TextBoxID="artist_TextBox"runat="server"Width="310px"AutoPostBack="True"CssClass="search_textbox"></asp:TextBox>

<
cc1:TextBoxWatermarkExtenderID="TextBoxWatermarkExtender"
runat="server"TargetControlID="artist_TextBox"WatermarkText="Start typing Artist name"WatermarkCssClass="watermark_extender">
</cc1:TextBoxWatermarkExtender>
 
<cc1:AutoCompleteExtenderID="search_TextBox_AutoCompleteExtender"runat="server"
CompletionInterval="250"CompletionSetCount="10"DelimiterCharacters=""
Enabled="True"MinimumPrefixLength="1"ServiceMethod="GetArtist"
ServicePath="../webService.asmx"TargetControlID="artist_TextBox"
CompletionListCssClass="AutoComplete"
CompletionListHighlightedItemCssClass="AutoCompleteHighlighted"
CompletionListItemCssClass="AutoCompleteListItem"
OnClientItemSelected="ACE_item_selected">
</cc1:AutoCompleteExtender>

 

<scripttype="text/javascript"language="javascript">
function ACE_item_selected(source, eventArgs )
{
alert(
" Artist : "+ eventArgs.get_text() +" - ID : "+eventArgs.get_value());
}
</script>

 

Footnote

&nbsp;
<asp:TextBoxID="footnoteTextBox"runat="server"Text='<%# Bind("footnote") %>'/>
<asp:SqlDataSourceID="ActDDLSqlDataSource"runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
onselecting="ActDDLSqlDataSource_Selecting"
SelectCommand="SELECT DISTINCT artist.artist_id, artist.aName, artist.owner, club.username FROM artist INNER JOIN club ON artist.owner = club.username WHERE (club.username = @club_username) ORDER BY artist.aName">
<SelectParameters>
<asp:ParameterName="club_username"/>
</SelectParameters>
</asp:SqlDataSource>
<br/>
<asp:LinkButtonID="InsertButton"runat="server"CausesValidation="True"CommandName="Insert"Text="Save"/>
&nbsp;<asp:LinkButtonID="InsertCancelButton"runat="server"CausesValidation="False"CommandName="Cancel"Text="Cancel"/>
</InsertItemTemplate>
</asp:FormView>

and the WEB SERVICE

[

WebMethod]
publicstring[] GetArtist(string prefixText)
{
int count = 10;
SqlConnection cn = newSqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
SqlCommand cmd = newSqlCommand("SELECT DISTINCT aName, artist_id FROM artist WHERE aName LIKE @term ", cn);
cmd.Parameters.AddWithValue(
"nrows", count);
cmd.Parameters.AddWithValue(
"term", prefixText +"%");// "%" +
List<string> suggestions =newList<string>();
cn.Open();
using (SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
{
while (dr.Read())//ACE returns text/value pair - set text to aName & Value to artist_id
suggestions.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem( dr[0].ToString(), dr[1].ToString() ));
} return suggestions.ToArray();
}

The web service works fine, it returns the name and ID from the DB, I have put a simple javascript alert box to display name & ID (which is fired by the autoCompleteExtenders OnClientItemSelected="ACE_item_selected"and the data come out OK

the  Name (text) is obviously displayed in the textBox with the autoCompleteExtender

but I just dont know how to get the  ID (value) into something I can bind to (so I can insert into my other gig DB)

Any help greatly aprreciated

thx

Tino


Viewing all articles
Browse latest Browse all 5678

Trending Articles