I forgot to mention that the TextBox and the DropDownList are inside a
GridView:
<asp:GridView ID="myGridView" runat="server"
AutoGenerateColumns="false"
AllowPaging="true" Width="300px" ShowFooter="true">
<Columns>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="NameLabel" runat="server" Text='<
%#Eval("Name") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:UpdatePanel ID="NamesListUpdatePanel"
runat="server">
<ContentTemplate>
<asp:TextBox ID="myTextBox"
OnTextChanged="myTextBox_TextChanged" AutoPostBack="true"
runat="server" />
<asp:DropDownList ID="myDDL"
runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Action">
<ItemTemplate>
<asp:LinkButton ID="DeleteLinkButton"
Text="Delete" runat="server" OnClick="DeleteLinkButton_Click" />
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="AddLinkButton" Text="Add"
runat="server" OnClick="AddLinkButton_Click" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
My code for populate the DropDownList is as follows:
Protected Sub myTextBox_TextChanged(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim selectSQL As String = "SELECT id, name FROM myTable WHERE
name LIKE @name + '%'"
Dim parent = DirectCast(sender, Control).Parent
Dim myTextBox = TryCast(parent.FindControl("myTextBox"),
TextBox)
Dim name As String = myTextBox.Text
Dim ddl = TryCast(parent.FindControl("myDDL"), DropDownList)
Dim DatabaseConnection As New SqlConnection
(ConfigurationManager.ConnectionStrings("myServer").ConnectionString)
Dim selectCMD As New SqlCommand(selectSQL, DatabaseConnection)
selectCMD.Parameters.Add(New SqlParameter("@name",
SqlDbType.VarChar))
selectCMD.Parameters("@name").Value = name
Dim adapter As New SqlDataAdapter
Dim dTable As New DataTable
adapter.SelectCommand = selectCMD
adapter.Fill(dTable)
ddl.DataSource = dTable
ddl.DataBind()
End Sub
I used the debug to go through the routine and everything seems to be
working well, but the DDL is not bound.
Any ideas of what is wrong? As well, this routine is fired only when I
click outside the textBox after type something on it. How do I do to
make the DDL to be bound when the user types something without needing
to click outside the textbox?
Other thing I just noticed is that: let's suppose I want to see all
people named ANA. When I type A, and click outside the TextBox, the
routine runs OK (however it doesn't bind my DDL). If decide to
continue and type N and click outside the TextBox, I have this error
message:
"Invalid postback or callback argument. Event validation is enabled
using <pages enableEventValidation="true"/> in configuration or <%@
Page EnableEventValidation="true" %> in a page. For security
purposes, this feature verifies that arguments to postback or callback
events originate from the server control that originally rendered
them. If the data is valid and expected, use the
ClientScriptManager.RegisterForEventValidation method in order to
register the postback or callback data for validation."
Does anyone know what is happening? I have no idea and really need
some help!
Thanks,
Ana
On Aug 10, 9:45 am, Ana <[email protected]> wrote:
> Hi,
>
> I'm new using ASP.NET/AJAX, so I'm having some difficulties developing
> my page. In this page, I have to have a DropDownList where the user
> can select multiple items (besides each item there will be a
> CheckBox). The difficult part for me, is that this DropDownList is
> populated based on what the user types on a TextBox. For example,
> supose the DropDownList will be populate with countries. If the user
> types A, the DDL will have all the countries starting with A. When he
> keeps typing and add and F, for example (now we will have AF), only
> the countries starting with AF will be in the list. And so on.
> I know I need to use AJAX to do this, but because I never used AJAX
> before, I don't know how to start. Can you please help me with this?
> I'm using VB.NET, ASP.NET 3.5 and Visual Studio 2008.
>
> I really appreciate your help!
>
> Ana