dropdownlist question

G

Guest

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.
 
I

Ignacio Machin \( .NET/ C# MVP \)

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,
 
G

Guest

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

Ignacio Machin ( .NET/ C# MVP ) said:
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 said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

dropdownlist 3
synchronization 2
dropdownlist question 2
printing a datagrid 2

Top