473,395 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

dynamic drop down list problem

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.d sDdl1)).BeginInit();
this.ddlLetter.SelectedIndexChanged += new
System.EventHandler(this.ddlLetter_SelectedIndexCh anged);
//
// 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.d sDdl1)).EndInit();

}
#endregion

private void ddlLetter_SelectedIndexChanged(object sender,
System.EventArgs e)
{

sqlDataAdapter1.GetFillParameters();
sqlDataAdapter1.Fill(dsDdl1);
ddlSubAgent.DataBind();
}
}
}

--
pmud
Nov 19 '05 #1
3 2032
Is there an error compiling or the page does not behave as expected?
--
Gopal Rangaswamy
Microsoft Certified Solutions Developer
FMS, Inc.
<http://www.fmsinc.com/consulting>
<http://www.fmsinc.com/dotnet/SourceBook/>

"pmud" <pm**@discussions.microsoft.com> wrote in message
news:0D**********************************@microsof t.com...
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.d sDdl1)).BeginInit();
this.ddlLetter.SelectedIndexChanged += new
System.EventHandler(this.ddlLetter_SelectedIndexCh anged);
//
// 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.d sDdl1)).EndInit();

}
#endregion

private void ddlLetter_SelectedIndexChanged(object sender,
System.EventArgs e)
{

sqlDataAdapter1.GetFillParameters();
sqlDataAdapter1.Fill(dsDdl1);
ddlSubAgent.DataBind();
}
}
}

--
pmud

Nov 19 '05 #2
Hi Gopal,

I solved that problem by using a data reader instead of data adapter. I
bound the second dropdown list to this data reader.

But I am facing problem with the SQL command to get values from the
Database.I am using the sqlCommand :
SELECT CustName FROM Table WHERE (CustName LIKE @x)

Here @x (the parameter) is the alphabet which the user selects from the
first dropdown list. Now, I want all CustNames which start with the letter
chosen by the user.

I tried the command with a % sign after the parameter like
SELECT CustName FROM Table WHERE (CustName LIKE @x%)
but it said Syntax is wrong. I even tried '@x*' and '@x%' , but nothing
seems to work.

What is the right syntax for this?

Thanks

"Gopal (FMS, Inc.)" wrote:
Is there an error compiling or the page does not behave as expected?
--
Gopal Rangaswamy
Microsoft Certified Solutions Developer
FMS, Inc.
<http://www.fmsinc.com/consulting>
<http://www.fmsinc.com/dotnet/SourceBook/>

"pmud" <pm**@discussions.microsoft.com> wrote in message
news:0D**********************************@microsof t.com...
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.d sDdl1)).BeginInit();
this.ddlLetter.SelectedIndexChanged += new
System.EventHandler(this.ddlLetter_SelectedIndexCh anged);
//
// 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.d sDdl1)).EndInit();

}
#endregion

private void ddlLetter_SelectedIndexChanged(object sender,
System.EventArgs e)
{

sqlDataAdapter1.GetFillParameters();
sqlDataAdapter1.Fill(dsDdl1);
ddlSubAgent.DataBind();
}
}
}

--
pmud


Nov 19 '05 #3
Hi,

I found out the answer . It was simple. The corerct syntax is:
SELECT CustName FROM Table WHERE (CustName LIKE @x + '%')

Thanks

"pmud" wrote:
Hi Gopal,

I solved that problem by using a data reader instead of data adapter. I
bound the second dropdown list to this data reader.

But I am facing problem with the SQL command to get values from the
Database.I am using the sqlCommand :
SELECT CustName FROM Table WHERE (CustName LIKE @x)

Here @x (the parameter) is the alphabet which the user selects from the
first dropdown list. Now, I want all CustNames which start with the letter
chosen by the user.

I tried the command with a % sign after the parameter like
SELECT CustName FROM Table WHERE (CustName LIKE @x%)
but it said Syntax is wrong. I even tried '@x*' and '@x%' , but nothing
seems to work.

What is the right syntax for this?

Thanks

"Gopal (FMS, Inc.)" wrote:
Is there an error compiling or the page does not behave as expected?
--
Gopal Rangaswamy
Microsoft Certified Solutions Developer
FMS, Inc.
<http://www.fmsinc.com/consulting>
<http://www.fmsinc.com/dotnet/SourceBook/>

"pmud" <pm**@discussions.microsoft.com> wrote in message
news:0D**********************************@microsof t.com...
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.d sDdl1)).BeginInit();
this.ddlLetter.SelectedIndexChanged += new
System.EventHandler(this.ddlLetter_SelectedIndexCh anged);
//
// 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.d sDdl1)).EndInit();

}
#endregion

private void ddlLetter_SelectedIndexChanged(object sender,
System.EventArgs e)
{

sqlDataAdapter1.GetFillParameters();
sqlDataAdapter1.Fill(dsDdl1);
ddlSubAgent.DataBind();
}
}
}

--
pmud


Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: C White | last post by:
I'm trying to write an asp script that will create a series of drop lists based on a table like: canada ontario toronto street name link canada ontario toronto road...
1
by: ayende | last post by:
Okay, I'm pretty sure that I'm doing everything right here, but something is very wrong in the result. I've a page that has a drop down list (with auto-post-back = true) and a place holder. ...
6
by: mcgrew.michael | last post by:
I hope this is the right group. I am very new to ASP so this is probably a stupid question. I have some vbscript that query's AD and populates a recordset. I know the recorset contains the...
0
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
2
by: Jim Gregg | last post by:
Hello all, I am faced with some logic that I am unsure how to handle. Imagine that I am running a WMI query and I am outputting the data into a dynamically created ASP table control. Here is my...
4
by: phcmi | last post by:
I have a PropertyGrid question. My task is to replace a legacy dialog box presentation with a modern one. The dialog itself allows the user to set configuration settings in our application, so...
9
by: Tarscher | last post by:
hi all, I have this seemingly simple problem. I have lost a lot of time on it though. When a user selects a value from a dropdownlist (static control) a dynamic control is generated. I have...
2
by: chobo | last post by:
Hi, I am trying to make a dynamic menu using javascript and an xml file. The structure of the page (test.html) is in the code below. When I load up the page the drop-down list is there, so I select a...
4
by: audreyality | last post by:
I am new to javascript and appreciate any guidance on this issue, so thank you in advance for your advice! Situation: I am working with a form that will send information to a database. I need the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.