G
Guest
Hi,
I have 2 drop down lists on an asp.Net page. The 1st contains alphabets.
When the user selects an alphabet frm the first list, the second drop down
list should be populated with names from the sql database, which begin with
that alphabet.
For this I used an sql data Adapter & created a data set. The user's
selection in 1st list is passed as parameter to the sql statement.
Please tell what is wrong with the following code?
public class WebForm3 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList ddlSubAgent;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected NEW.dsDdl dsDdl1;
protected System.Web.UI.WebControls.DropDownList ddlLetter;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.dsDdl1 = new NEW.dsDdl();
((System.ComponentModel.ISupportInitialize)(this.dsDdl1)).BeginInit();
this.ddlLetter.SelectedIndexChanged += new
System.EventHandler(this.ddlLetter_SelectedIndexChanged);
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=TR;packet
size=4096;user id=sa;data source=TR;persist secu" +
"rity info=True;initial catalog=ALOG;password=aaa";
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new
System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table",
"FormFields", new System.Data.Common.DataColumnMapping[] { new
System.Data.Common.DataColumnMapping("SubAgentName", "SubAgentName")})});
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT SubAgentName FROM FormFields
WHERE (SubAgentName LIKE @x)";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
this.sqlSelectCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@x", System.Data.SqlDbType.VarChar, 30,
"SubAgentName"));
//
// dsDdl1
//
this.dsDdl1.DataSetName = "dsDdl";
this.dsDdl1.Locale = new System.Globalization.CultureInfo("en-US");
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.dsDdl1)).EndInit();
}
#endregion
private void ddlLetter_SelectedIndexChanged(object sender,
System.EventArgs e)
{
sqlDataAdapter1.GetFillParameters();
sqlDataAdapter1.Fill(dsDdl1);
ddlSubAgent.DataBind();
}
}
}
I have 2 drop down lists on an asp.Net page. The 1st contains alphabets.
When the user selects an alphabet frm the first list, the second drop down
list should be populated with names from the sql database, which begin with
that alphabet.
For this I used an sql data Adapter & created a data set. The user's
selection in 1st list is passed as parameter to the sql statement.
Please tell what is wrong with the following code?
public class WebForm3 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList ddlSubAgent;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected NEW.dsDdl dsDdl1;
protected System.Web.UI.WebControls.DropDownList ddlLetter;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.dsDdl1 = new NEW.dsDdl();
((System.ComponentModel.ISupportInitialize)(this.dsDdl1)).BeginInit();
this.ddlLetter.SelectedIndexChanged += new
System.EventHandler(this.ddlLetter_SelectedIndexChanged);
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=TR;packet
size=4096;user id=sa;data source=TR;persist secu" +
"rity info=True;initial catalog=ALOG;password=aaa";
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new
System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table",
"FormFields", new System.Data.Common.DataColumnMapping[] { new
System.Data.Common.DataColumnMapping("SubAgentName", "SubAgentName")})});
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT SubAgentName FROM FormFields
WHERE (SubAgentName LIKE @x)";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
this.sqlSelectCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@x", System.Data.SqlDbType.VarChar, 30,
"SubAgentName"));
//
// dsDdl1
//
this.dsDdl1.DataSetName = "dsDdl";
this.dsDdl1.Locale = new System.Globalization.CultureInfo("en-US");
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.dsDdl1)).EndInit();
}
#endregion
private void ddlLetter_SelectedIndexChanged(object sender,
System.EventArgs e)
{
sqlDataAdapter1.GetFillParameters();
sqlDataAdapter1.Fill(dsDdl1);
ddlSubAgent.DataBind();
}
}
}