Click to See Complete Forum and Search --> : Calling varibles


kicken18
07-13-2007, 04:29 AM
I think I am just going absolutly crazy, but got some problems, Here is the code

For Each Dr In DSPageData.Tables("All").Rows
PKey = (Dr("PKey"))
'Response.Write(PKey)
TName = (Dr("TName"))
'Response.Write(TName)

DBDataAdapter = New SqlDataAdapter("SELECT " & PKey & " FROM " & TName & "", DBConn)
DBDataAdapter.Fill(DSPageData, "Courses")
Dim dropdown As String = "ddl" & PKey & ".DataSource = DSPageData.Tables('Courses').DefaultView"
Dim databind As String = "ddl" & PKey & ".DataBind()"
....
<asp:DropDownList ID="ddlAOE" Runat="server" DataTextField="AOE" />
<asp:DropDownList ID="ddlCM" runat="server" DataTextField="CM" />
<asp:dropdownlist ID="ddlADC" runat="server" DataTextField="ADC" />


Now, my dropdownlist appear when I run the page, obviouslly, but they are not populated. IF I uncomment my response.write bits near the top, I get back what expect, so my sql is working, but my dad isn't binding to the dropdown lists. I think it has something to do with my databind var's, I am assinging them my value, but maybe I am not calling them? As in a classic sense it would be like

DBDataAdapter = New SqlDataAdapter("SELECT Department FROM TBL_Department", DBConn)
DBDataAdapter.Fill(DSPageData, "Department")
DeptDropDown.DataSource = DSPageData.Tables("Department").DefaultView
DeptDropDown.DataBind()

lmf232s
07-13-2007, 09:19 AM
Well it looks like your trying to build the name of the dropdownlist on the fly.
In order to do this your going to have to make a reference to the control and find that control on the page.

Your going to have to play around with how to pull this off because my example assumes you have your drop downs with in a panel so there for we look for the controls with in the panel and not the page. In order to search the page for the control you have to do a recursive search to locate the control which Im not sure thats what your looking for as you would have to loop every control on the page till you find all the drop downs.

Any way this works and is along the lines of what you need to do.


<asp:Panel ID="pnlTest" runat="server">
<asp:DropDownList ID="ddlAOE" Runat="server" />
<asp:DropDownList ID="ddlCM" runat="server" />
<asp:dropdownlist ID="ddlADC" runat="server" />
</asp:Panel>

'This works
Dim ddl As DropDownList = CType(Me.pnlTest.FindControl("ddlAOE"), DropDownList)
'This is what you would do
'Dim ddl As DropDownList = CType(Me.pnlTest.FindControl("ddl" & PKey), DropDownList)
With ddl
'Just showing you that I now have a reference to the contorl.
.DataSource = ?
.Databind()
.Items.Insert(0, New ListItem("Select", ""))
End With

kicken18
07-13-2007, 09:43 AM
ooo this is getting complicated :S

Basically, I need to get data from my TBL_ALL table, this contains all of the table and primary key names in my database. Then with all this data, build an sql search for each row and populate a dropdownlist. The dropdownlist won't be on the page, these will be created using a loop as well, so the whole page will be created using a loop (don't ask why, manager was moaning *shakes fist*

For testing purposes I have manually created the the dropdownlist, so I can get the loop to populate them working, then move on to dynamically creating the actual drop down list's themselves (I hope you make sense of all of that)

So while this search thing is a nice idea, it won't work in the finished product. I have never heard of this panel thing though, maybe I will check that out!

So I guess logically it would be like:
Get data from TBL_All
For each row returned
create sql statement
create dataset with results
bind to drop down list
Next row

.
.
.
<html>
<%
For each row
create <asp:dropdownlist id=row runat="Server" datavaluefield=row />
Next
%>

Hope that makes a bit more sense?

Chris