dynamic dropdown lists

A

Anthony

So I've got three dropdowns in a datagrid footer (to add records). I need
them to cascade, in the first one I have three choices, in the second one I
have anywhere from 3 to 10 choices, depending on what is selected in the
first one, etc, etc.

Whats happening is that when the auto-postback occurs, it fires the event
for the dropdownlist change, which calls the Getxxx routines that update the
dropdownlist's datasource to the new datatable (from a query). Then it turns
around and fires the Getxxxx routines again, with the default values when
the page is being created. I cant figure out a way to solve this
double-execution thats going on.... Any help? Thanks in advance. Code is
below...

-Anthony

PS: I've verified that my queries do return the correct data, I've steped
through the code and verified that. Also, when creating the dropdownlists in
the footer of the datagrid, I cant seem to access them from the code-behind
file (even though they are there in the aspx file, the code behind file has
no variable declaration for them, and attempts to put them in dont work),
which is why i have to use the datagrid item to access the footer and then
..FindControl them.

I've got my dropdown lists in the ASPX file as follows...

[...]

<asp:DropDownList id="ddlTask" runat="server" AutoPostBack="True"
DataValueField="TASK" DataTextField="TASK"
DataSource='<%# GetTasks() %>'
OnSelectedIndexChanged="ddlTask_SelectedIndexChange"/>

[...]

<asp:DropDownList id="ddlDrwgtype" runat="server" AutoPostBack="True"
DataValueField="DRWGTYPE" DataTextField="DRWGTYPE"
DataSource='<%# GetDrwgType("") %>'
OnSelectedIndexChanged="ddlDrwgtype_SelectedIndexChange"/>

[...]

<asp:DropDownList id="ddlStep" runat="server"
DataValueField="STEP" DataTextField="STEP"
DataSource='<%# GetStep("","") %>' />

[...]



In the code-behind file, the routines are as follows...
Protected WithEvents newtask As OleDb.OleDbDataAdapter
Protected WithEvents newdrwgtype As OleDb.OleDbDataAdapter
Protected WithEvents newstep As OleDb.OleDbDataAdapter

[...]

Public Function GetTasks() As DataTable
newtask.Fill(dstask, "TASKLUT")
Return dstask.Tables("TASKLUT")
End Function

Public Function GetDrwgType(ByVal task As String) As DataTable
If task = "" Then task = "FACILITIES"
newdrwgtype.SelectCommand.Parameters("TASK").Value = task
If dstask.Tables.Contains("DRWGTYPELUT") Then
dstask.Tables.Remove("DRWGTYPELUT")
End If
newdrwgtype.Fill(dstask, "DRWGTYPELUT")
Return dstask.Tables("DRWGTYPELUT")
End Function

Public Function GetStep(ByVal task As String, ByVal drwgtype As String)
As DataTable
If task = "" Then task = "FACILITIES"
If drwgtype = "" Then drwgtype = "600MAP"
If dstask.Tables.Contains("STEPLUT") Then
dstask.Tables.Remove("STEPLUT")
End If
newstep.SelectCommand.Parameters("TASK").Value = task
newstep.SelectCommand.Parameters("DRWGTYPE").Value = drwgtype
newstep.Fill(dstask, "STEPLUT")
Return dstask.Tables("STEPLUT")
End Function

Public Sub ddlTask_SelectedIndexChange(ByVal sender As Object, ByVal e
As EventArgs)
Dim ddltask As DropDownList = sender
Dim dgFooter As DataGridItem = ddltask.Parent.Parent
Dim ddlDrwgtype As DropDownList =
dgFooter.FindControl("ddldrwgtype")
Dim task As String = ddltask.SelectedValue


ddlDrwgtype.DataSource = GetDrwgType(task)
ddlDrwgtype.DataBind()
End Sub

Public Sub ddlDrwgtype_SelectedIndexChange(ByVal sender As Object, ByVal
e As EventArgs)
Dim ddldrwgtype As DropDownList = sender
Dim dgFooter As DataGridItem = ddldrwgtype.Parent.Parent
Dim ddltask As DropDownList = dgFooter.FindControl("ddltask")
Dim ddlstep As DropDownList = dgFooter.FindControl("ddlstep")

Dim task As String = ddltask.SelectedValue
Dim drwgtype As String = ddldrwgtype.SelectedValue

ddlstep.DataSource = GetStep(task, drwgtype)
ddlstep.DataBind()
End Sub
 

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

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top