Hi...
I have a user control that is basically a dropdownlist populate by a database, but its used on many pages...
It display on the pages i use it on fine, and it validates correctly, but i can't seem to get the data out of it in code (on the page the control is *used* on).
I've tried this, among other things, with no luck:
CountryList1.Items[CountryList1.SelectedIndex].Value
here is the control in the page i use it on:
<COUNTRIES:CountryList id="CountryList1" runat="server"></COUNTRIES:CountryList>
the tag is registered fine.
here is the user control:
<%@ Control Language="VB" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
ShowCountries()
End Sub
Sub ShowCountries()
Dim conn As SqlConnection
Dim DS as DataSet
Dim sql As SqlDataAdapter
Dim TotalRows, r as Integer
Dim strConn As String = "server=(local);database=BusinessMeetings;user id=sa"
conn = New SQLConnection(strConn)
sql = New SqlDataAdapter("SELECT countryid, countryname FROM countries ORDER BY countryname", conn)
DS = new DataSet()
sql.Fill(DS, "countries"
'total rows for loop
Dim GetRows As DataTable = DS.Tables ("countries"
TotalRows = GetRows.Rows.Count
'create default and set it
Me.ddCountries.Items.Add(New ListItem("Choose a Country", "")
ddCountries.SelectedIndex = 0
'fill 'er up
For r = 0 To TotalRows-1
Me.ddCountries.Items.Add(New ListItem(GetRows.Rows(r)(1).ToString(), GetRows.Rows(r)(0).ToString()))
Next
conn.Close : conn = Nothing
sql = Nothing : sql = Nothing
End Sub
</script>
<aspropDownList id="ddCountries" runat="server"></aspropDownList>
<asp:RequiredFieldValidator id="CountryValidator" Runat="server" ErrorMessage="Country Required" ControlToValidate="ddCountries" Display="None"></asp:RequiredFieldValidator>
any ideas???
THANKS.
I have a user control that is basically a dropdownlist populate by a database, but its used on many pages...
It display on the pages i use it on fine, and it validates correctly, but i can't seem to get the data out of it in code (on the page the control is *used* on).
I've tried this, among other things, with no luck:
CountryList1.Items[CountryList1.SelectedIndex].Value
here is the control in the page i use it on:
<COUNTRIES:CountryList id="CountryList1" runat="server"></COUNTRIES:CountryList>
the tag is registered fine.
here is the user control:
<%@ Control Language="VB" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
ShowCountries()
End Sub
Sub ShowCountries()
Dim conn As SqlConnection
Dim DS as DataSet
Dim sql As SqlDataAdapter
Dim TotalRows, r as Integer
Dim strConn As String = "server=(local);database=BusinessMeetings;user id=sa"
conn = New SQLConnection(strConn)
sql = New SqlDataAdapter("SELECT countryid, countryname FROM countries ORDER BY countryname", conn)
DS = new DataSet()
sql.Fill(DS, "countries"
'total rows for loop
Dim GetRows As DataTable = DS.Tables ("countries"
TotalRows = GetRows.Rows.Count
'create default and set it
Me.ddCountries.Items.Add(New ListItem("Choose a Country", "")
ddCountries.SelectedIndex = 0
'fill 'er up
For r = 0 To TotalRows-1
Me.ddCountries.Items.Add(New ListItem(GetRows.Rows(r)(1).ToString(), GetRows.Rows(r)(0).ToString()))
Next
conn.Close : conn = Nothing
sql = Nothing : sql = Nothing
End Sub
</script>
<aspropDownList id="ddCountries" runat="server"></aspropDownList>
<asp:RequiredFieldValidator id="CountryValidator" Runat="server" ErrorMessage="Country Required" ControlToValidate="ddCountries" Display="None"></asp:RequiredFieldValidator>
any ideas???
THANKS.