I
Iain
Hi All
I have 2 DropDownList boxes on a page.
The first (id= "Operation") is populated on PageLoad with the contents
of a database table.
The second id="WorkStations" will not be populated until the first has
been changed
The definitions are below.
<ASP
ropDownList id="Operation"
runat="server"
AppendDataBoundItems="True"
AutoPostBack="True"
OnSelectedIndexChanged="Operation_SelectedIndexChanged">
</ASP
ropDownList>
<ASP
ropDownList id="WorkStations"
runat="server"
AppendDataBoundItems="True"
AutoPostBack="True"
OnSelectedIndexChanged="WorkStations_SelectedIndexChanged">
</ASP
ropDownList>
..
Both events fire successfully - on every item change.
When I change the Operation box it fires correctly and the WorkStations
box is populated correctly. However when I select an item in the
WorkStations box none of the items are listed as Selected in the event
handler. The event fires - I am using Delphi Developer Studio 2006 to
develop and I have debugged the event handler - and the dropdownlist
box is being picked up.
The 2 event handlers are
protected void Operation_SelectedIndexChanged(object sender, EventArgs
e)
{
OleDbConnection conoper = new OleDbConnection("provider=IBMDA400;Data
Source=xx.xxx.xx.xxx;User Id=xxxxxxx;password=xxxxxxxxxx");
OleDbCommand cmdoper = new OleDbCommand();
string LString;
foreach(ListItem item in Operation.Items) // This is dropdownlist
box 1
{
if(item.Selected)
{
if (item.Value == "Please Select An Operation")
{
LString = "<script language=JavaScript>alert('No Operation Selected.
\n Please Select An Operation');</script>";
RegisterStartupScript("startupScript", LString);
}
else
{
LString = "<script language=JavaScript>alert('" + item.Value +
"');</script>";
conoper.Open();
cmdoper.Connection = conoper;
cmdoper.CommandType = CommandType.Text;
LString = "select * from WRKINSTRUC.WORKSTATN Where OPERNAME = '" +
item.Value + "'";
cmdoper.CommandText = LString;
OleDbDataReader dsWorkCenters = cmdoper.ExecuteReader();
WorkStations.DataSource = dsWorkCenters;
WorkStations.DataTextField = "WORKSTATN";
WorkStations.DataValueField = "WORKSTATN";
WorkStations.DataBind();
conoper.Close();
WorkStations.Items.Insert(0, new ListItem("Please Select A
Workstation", "0"));
WorkStations.SelectedIndex = 0;
}
}
}
}
protected void WorkStations_SelectedIndexChanged(object sender,
EventArgs e) // This is dropdownlist box 2
{
string LString;
int indexNum;
indexNum = WorkStations.SelectedIndex;
Response.Write(indexNum );
foreach(ListItem item in WorkStations.Items)
{
if(item.Selected)
{
if (item.Value == "Please Select A Workstation")
{
LString = "<script language=JavaScript>alert('No Workstation
Selected. \n Please Select A Workstation');</script>";
RegisterStartupScript("startupScript", LString);
}
else
{
LString = "<script language=JavaScript>alert('" + item.Text +
"');</script>";
RegisterStartupScript("startupScript", LString);
}
}
}
}
As I am new to C# and ASP.NET could anyone please give me an idea of
what is going wrong here
Thanks in advance for any assistance offered
Iain
I have 2 DropDownList boxes on a page.
The first (id= "Operation") is populated on PageLoad with the contents
of a database table.
The second id="WorkStations" will not be populated until the first has
been changed
The definitions are below.
<ASP
![Big Grin :D :D](/styles/default/custom/smilies/grin.gif)
runat="server"
AppendDataBoundItems="True"
AutoPostBack="True"
OnSelectedIndexChanged="Operation_SelectedIndexChanged">
</ASP
![Big Grin :D :D](/styles/default/custom/smilies/grin.gif)
<ASP
![Big Grin :D :D](/styles/default/custom/smilies/grin.gif)
runat="server"
AppendDataBoundItems="True"
AutoPostBack="True"
OnSelectedIndexChanged="WorkStations_SelectedIndexChanged">
</ASP
![Big Grin :D :D](/styles/default/custom/smilies/grin.gif)
..
Both events fire successfully - on every item change.
When I change the Operation box it fires correctly and the WorkStations
box is populated correctly. However when I select an item in the
WorkStations box none of the items are listed as Selected in the event
handler. The event fires - I am using Delphi Developer Studio 2006 to
develop and I have debugged the event handler - and the dropdownlist
box is being picked up.
The 2 event handlers are
protected void Operation_SelectedIndexChanged(object sender, EventArgs
e)
{
OleDbConnection conoper = new OleDbConnection("provider=IBMDA400;Data
Source=xx.xxx.xx.xxx;User Id=xxxxxxx;password=xxxxxxxxxx");
OleDbCommand cmdoper = new OleDbCommand();
string LString;
foreach(ListItem item in Operation.Items) // This is dropdownlist
box 1
{
if(item.Selected)
{
if (item.Value == "Please Select An Operation")
{
LString = "<script language=JavaScript>alert('No Operation Selected.
\n Please Select An Operation');</script>";
RegisterStartupScript("startupScript", LString);
}
else
{
LString = "<script language=JavaScript>alert('" + item.Value +
"');</script>";
conoper.Open();
cmdoper.Connection = conoper;
cmdoper.CommandType = CommandType.Text;
LString = "select * from WRKINSTRUC.WORKSTATN Where OPERNAME = '" +
item.Value + "'";
cmdoper.CommandText = LString;
OleDbDataReader dsWorkCenters = cmdoper.ExecuteReader();
WorkStations.DataSource = dsWorkCenters;
WorkStations.DataTextField = "WORKSTATN";
WorkStations.DataValueField = "WORKSTATN";
WorkStations.DataBind();
conoper.Close();
WorkStations.Items.Insert(0, new ListItem("Please Select A
Workstation", "0"));
WorkStations.SelectedIndex = 0;
}
}
}
}
protected void WorkStations_SelectedIndexChanged(object sender,
EventArgs e) // This is dropdownlist box 2
{
string LString;
int indexNum;
indexNum = WorkStations.SelectedIndex;
Response.Write(indexNum );
foreach(ListItem item in WorkStations.Items)
{
if(item.Selected)
{
if (item.Value == "Please Select A Workstation")
{
LString = "<script language=JavaScript>alert('No Workstation
Selected. \n Please Select A Workstation');</script>";
RegisterStartupScript("startupScript", LString);
}
else
{
LString = "<script language=JavaScript>alert('" + item.Text +
"');</script>";
RegisterStartupScript("startupScript", LString);
}
}
}
}
As I am new to C# and ASP.NET could anyone please give me an idea of
what is going wrong here
Thanks in advance for any assistance offered
Iain