I really need some help. I've spent the past two hours trying to figure this out... and I can't. I don't know what I'm doing wrong.
This is on my Default.aspx page:
<asp:DropDownList ID="ddlMagazineList" runat="server" DataSourceID="MagazinesDataSource" OnSelectedIndexChanged="updateKey(this.value);"
DataTextField="Name" DataValueField="Id">
</asp:DropDownList><asp:SqlDataSource ID="MagazinesDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="Get_Magazine_List" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
<asp:Panel ID="panel1" style='width:100px; height:100px' BorderWidth='1' runat='server'>
</asp:Panel>
<ajaxToolkit:DynamicPopulateExtender ID="dp1" runat="server"
TargetControlID="panel1"
ClearContentsDuringUpdate="true"
ServiceMethod="GetHtml"
UpdatingCssClass="dynamicPopulate_Updating" />
On the code behind, I have the following:
...
using System.Web.Services;
using System.Web.Script.Services;
using System.IO;
using AjaxControlToolkit;
...
public partial class _Default : System.Web.UI.Page
{
[WebMethod]
public string GetHtml(string contextKey)
{
System.Threading.Thread.Sleep(1000);
string html = GetProducts(Convert.ToInt32(contextKey));
return html;
}
private string GetProducts(int categoryID)
{
string connectionString = "Server=localhost;Database=Northwind;Trusted_Connection=true";
SqlConnection myConnection = new SqlConnection(connectionString);
SqlCommand myCommand = new SqlCommand("SELECT ProductID, ProductName FROM Products WHERE CategoryID = @CategoryID", myConnection);
myCommand.Parameters.AddWithValue("@CategoryID", categoryID);
SqlDataAdapter ad = new SqlDataAdapter(myCommand);
DataSet ds = new DataSet();
ad.Fill(ds);
GridView gv = new GridView();
gv.ID = "GridView1";
gv.DataSource = ds;
gv.DataBind();
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gv.RenderControl(htw);
htw.Close();
return sw.ToString();
}
}
Running that, I get the error CS1026: ) expected in regards to the OnSelectedIndexChanged="updateKey(this.value);"
I've also tried removing that from the DropDownList and changing the DynamicPopulateExtender to:
<ajaxToolkit:DynamicPopulateExtender ID="dp1" runat="server"
TargetControlID="panel1"
PopulateTriggerControlID="ddlMagazineList"
ClearContentsDuringUpdate="true"
ServiceMethod="GetHtml"
UpdatingCssClass="dynamicPopulate_Updating" />
This doesn't give a .NET error, but when you select something it returns "Web Service call failed: 500."
In my opinion, that is a horrible error for me... as I have no idea WHY it failed.
I really don't know... if someone could point me in the right direction I would really, truly appreciate it! Thank you!
Sincerely,
Andrew Tatum