473,408 Members | 2,444 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,408 software developers and data experts.

dropdownlist question

I have a C# asp.net webform that contains a dropdownlist and a button that
allows the user to select another item in the dropdownlist. The webform
should work as follows:

When the user selects an item in the dropdownlist and clicks the button, his
selection will appear as a line of text somewhere in the webform. The user
can then select another item and clicks the button and his selection will
again appear as a line of text.

In order to avoid duplication, I need to remove (or disable) the selected
item from the dropdownlist. That way, the user wont be able to select an item
that he previously selected. I need to do this without modifying the
database. My code follows and thanks in advance.

string sCCI = "SELECT activity_no,des1
category,Convert(activity_uom,'US7ASCII') bill_rate "
+ "FROM pa_activity "
+ "WHERE (activity_no LIKE Upper('D0%') or activity_no LIKE Upper('S0%'))
And last_status <> 'D' "
+ " And activity_type = 'L' "
+ "ORDER BY des1 ";
OracleConnection oraConn = new OracleConnection(connStr);
OracleCommand oraCMD = new OracleCommand(sCCI, oraConn);
oraConn.Open();
OracleDataAdapter adapter = new OracleDataAdapter(oraCMD);
DataSet ds = new DataSet();
adapter.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
ddlConsultantCategory.DataSource = ds.Tables[0];
ddlConsultantCategory.DataTextField = "category";
ddlConsultantCategory.DataValueField = "category";
ddlConsultantCategory.DataBind();
ddlConsultantCategory.Items.Insert(0, "(Select Consultant Category)");
}
oraConn.Close();

where ddlConsultantCategory is the dropdownlist.

Nov 17 '05 #1
2 2346
Hi,
Use DropDownList.Items.Remove ( DropDownList1.SelectedItem ) or
DropDownList.Items.RemoveAt ( DropDownList1.SelectedIndex )
BTW, the code you posted is only the DB access portion, do you have problem
with it?
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Newbie" <Ne****@discussions.microsoft.com> wrote in message
news:EE**********************************@microsof t.com...
I have a C# asp.net webform that contains a dropdownlist and a button that
allows the user to select another item in the dropdownlist. The webform
should work as follows:

When the user selects an item in the dropdownlist and clicks the button,
his
selection will appear as a line of text somewhere in the webform. The
user
can then select another item and clicks the button and his selection will
again appear as a line of text.

In order to avoid duplication, I need to remove (or disable) the selected
item from the dropdownlist. That way, the user wont be able to select an
item
that he previously selected. I need to do this without modifying the
database. My code follows and thanks in advance.

string sCCI = "SELECT activity_no,des1
category,Convert(activity_uom,'US7ASCII') bill_rate "
+ "FROM pa_activity "
+ "WHERE (activity_no LIKE Upper('D0%') or activity_no LIKE Upper('S0%'))
And last_status <> 'D' "
+ " And activity_type = 'L' "
+ "ORDER BY des1 ";
OracleConnection oraConn = new OracleConnection(connStr);
OracleCommand oraCMD = new OracleCommand(sCCI, oraConn);
oraConn.Open();
OracleDataAdapter adapter = new OracleDataAdapter(oraCMD);
DataSet ds = new DataSet();
adapter.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
ddlConsultantCategory.DataSource = ds.Tables[0];
ddlConsultantCategory.DataTextField = "category";
ddlConsultantCategory.DataValueField = "category";
ddlConsultantCategory.DataBind();
ddlConsultantCategory.Items.Insert(0, "(Select Consultant Category)");
}
oraConn.Close();

where ddlConsultantCategory is the dropdownlist.

Nov 17 '05 #2
Thanks a lot, sir. It's working! I do have another question which I'll post
later.

"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,
Use DropDownList.Items.Remove ( DropDownList1.SelectedItem ) or
DropDownList.Items.RemoveAt ( DropDownList1.SelectedIndex )
BTW, the code you posted is only the DB access portion, do you have problem
with it?
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Newbie" <Ne****@discussions.microsoft.com> wrote in message
news:EE**********************************@microsof t.com...
I have a C# asp.net webform that contains a dropdownlist and a button that
allows the user to select another item in the dropdownlist. The webform
should work as follows:

When the user selects an item in the dropdownlist and clicks the button,
his
selection will appear as a line of text somewhere in the webform. The
user
can then select another item and clicks the button and his selection will
again appear as a line of text.

In order to avoid duplication, I need to remove (or disable) the selected
item from the dropdownlist. That way, the user wont be able to select an
item
that he previously selected. I need to do this without modifying the
database. My code follows and thanks in advance.

string sCCI = "SELECT activity_no,des1
category,Convert(activity_uom,'US7ASCII') bill_rate "
+ "FROM pa_activity "
+ "WHERE (activity_no LIKE Upper('D0%') or activity_no LIKE Upper('S0%'))
And last_status <> 'D' "
+ " And activity_type = 'L' "
+ "ORDER BY des1 ";
OracleConnection oraConn = new OracleConnection(connStr);
OracleCommand oraCMD = new OracleCommand(sCCI, oraConn);
oraConn.Open();
OracleDataAdapter adapter = new OracleDataAdapter(oraCMD);
DataSet ds = new DataSet();
adapter.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
ddlConsultantCategory.DataSource = ds.Tables[0];
ddlConsultantCategory.DataTextField = "category";
ddlConsultantCategory.DataValueField = "category";
ddlConsultantCategory.DataBind();
ddlConsultantCategory.Items.Insert(0, "(Select Consultant Category)");
}
oraConn.Close();

where ddlConsultantCategory is the dropdownlist.


Nov 17 '05 #3

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

Similar topics

2
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of...
1
by: | last post by:
This is a crosspost from a less-frequented (but more focused) asp.net group; I didn't receive an answer that worked. I'd like to get this form functional. Could someone help on what's probably a...
3
by: Tim::.. | last post by:
Can someone please tell me how I go about preselecting an item in a drop drown list when I click the Edit Command in a datagrid? I have tried the following but it doesn't work for me! I would...
6
by: Julius Fenata | last post by:
Dear all, I have created client-side scripting to trigger event onChange from code-behind, like this: DropDownList1.Attributes = "GenerateArticleID()"; At the script on Windows Form, I...
1
by: Phil | last post by:
I would like to make the CreateUserWizard's security question box display as a databound (xml file) dropdownlist. I can make the dropdownlist display by using a contenettemplate, but I can't get...
0
by: Juanjo | last post by:
Hi, Before, I was working with Asp.net 1.0 and datagrid. I posted a question for this issue. The solution of this problem is load the second dropdownlist on the selectedindexchanged event of the...
4
by: glenn | last post by:
Hi folks, I am getting an error "Object reference not set to an instance of an object". It seems I have everything in place but something is obviously in err. If you could take a quick peak...
1
by: DJ | last post by:
I have a DropDownList in Visual Web Developer that is databound to a SQL Database. Whenever the web page is opened the DropDownList is automatically filled with the first item in the table. My...
6
by: shashi shekhar singh | last post by:
Respected Sir, I have to create multiple dynamic dropdownlist boxes and add items dynamically in <asp:table> server control but problem occurs , i.e. except of fist dropdown list no dropdownlist...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.