H
HH
Hi,
I have a dropdown list that is datafilled via a SQL table.
The text part is always unique. (A list of countries)
Each country is assigned one of three numbers. (This being the 'value'
of the ddl.)
ie:
Country Value
Australia 1
Canada 2
USA 3
Kenya 1
UK 3
When a user selects a country say "UK" i want to store that country
name and value. But when pressing submit, the value stored is "USA, 3"
Looking around google, it seems that the ddl always takes the first
unique value in the table. Has anyone else come across this and more
importantly found a way around it???
Thanking you all in advance
H
*** Codebehind ***
namespace datafill {
public class countries : Page {
public DropDownList ddlCountries1;
public Label lblTime;
protected void Page_Load(Object Src, EventArgs E) {
if (!IsPostBack){
SQL CONNECTION AND QUERY GOES HERE
SqlDataAdapter myCommand1 = new SqlDataAdapter("SELECT * FROM
ycQryCountries", myConnection);
DataSet ds1 = new DataSet();
myCommand1.Fill(ds1, "CountriesList");
ddlCountries1.DataSource = ds1.Tables["CountriesList"].DefaultView;
ddlCountries1.DataTextField = "Country";
ddlCountries1.DataValueField = "TimeRange");
ddlCountries1.DataBind();
//close the sql connection
myConnection.Close();
}
if (IsPostBack){
Page.DataBind();
}
}
*** aspx page ****
<aspropDownList ID="ddlCountries1" CssClass="ddl" runat="server"
Width="180"></aspropDownList>
<br>
<asp:Button ID="btnSubmit" Text="Submit" runat="server"
OnClick="ddlChange" />
</p>
<asp:label Font-Bold="true" text='<%# ddlCountries1.SelectedItem.Text
%>' runat="server"/><br><br>
<br>
<asp:label ID="lblTime" text='<%# ddlCountries1.SelectedItem.Value %>'
runat="server"/>
I have a dropdown list that is datafilled via a SQL table.
The text part is always unique. (A list of countries)
Each country is assigned one of three numbers. (This being the 'value'
of the ddl.)
ie:
Country Value
Australia 1
Canada 2
USA 3
Kenya 1
UK 3
When a user selects a country say "UK" i want to store that country
name and value. But when pressing submit, the value stored is "USA, 3"
Looking around google, it seems that the ddl always takes the first
unique value in the table. Has anyone else come across this and more
importantly found a way around it???
Thanking you all in advance
H
*** Codebehind ***
namespace datafill {
public class countries : Page {
public DropDownList ddlCountries1;
public Label lblTime;
protected void Page_Load(Object Src, EventArgs E) {
if (!IsPostBack){
SQL CONNECTION AND QUERY GOES HERE
SqlDataAdapter myCommand1 = new SqlDataAdapter("SELECT * FROM
ycQryCountries", myConnection);
DataSet ds1 = new DataSet();
myCommand1.Fill(ds1, "CountriesList");
ddlCountries1.DataSource = ds1.Tables["CountriesList"].DefaultView;
ddlCountries1.DataTextField = "Country";
ddlCountries1.DataValueField = "TimeRange");
ddlCountries1.DataBind();
//close the sql connection
myConnection.Close();
}
if (IsPostBack){
Page.DataBind();
}
}
*** aspx page ****
<aspropDownList ID="ddlCountries1" CssClass="ddl" runat="server"
Width="180"></aspropDownList>
<br>
<asp:Button ID="btnSubmit" Text="Submit" runat="server"
OnClick="ddlChange" />
</p>
<asp:label Font-Bold="true" text='<%# ddlCountries1.SelectedItem.Text
%>' runat="server"/><br><br>
<br>
<asp:label ID="lblTime" text='<%# ddlCountries1.SelectedItem.Value %>'
runat="server"/>