DropDownList - SelectedValue - Am I dummy ?

Arch4ngel

Senior Contributor
Joined
Mar 22, 2004
Messages
940
Location
Montreal, QC
Ok... I'm enough experimented in ASP.NET but I think that my dummy brain is running a bit like a square today...

Here's what I wanna know :

I have 3 DDL that are Databound and I make 3 different selection.
After, I click on the button "Confirm" and when I use cmb.SelectedValue it always return 1 or the value of the first item (values are different for each item).

Eg :
WinNt == 1
WinXP == 2
Win98 == 3
If I select Win98 it'll show me 1... (Doh ! :confused: ) It's a big problem because all of this will eventually be entered in a DB.

So if anyone could help me !

Thanks a lot.
 
Are you databinding in the page_load event? If so you need to check Page.IsPostback and only databind when it is false. If that doesn't fix the problem could you post the relevant parts of your code?
 
here it is

PlausiblyDamp said:
Are you databinding in the page_load event? If so you need to check Page.IsPostback and only databind when it is false. If that doesn't fix the problem could you post the relevant parts of your code?
Code:
[size=2][size=2]pein = Session["pein"] == [/size][size=2][color=#0000ff]null[/color][/size][size=2] ? "" : Session["pein"].ToString();
 
[/size][size=2][color=#0000ff]if[/color][/size][size=2]( pein == "" )
 
Response.Redirect("User.aspx");
 
dsLocations.EnforceConstraints = [/size][size=2][color=#0000ff]false[/color][/size][size=2];
 
adapFournisseur.Fill( dsLocations, "SelectFournisseur" );
 
adapModele.Fill( dsLocations, "SelectModele" );
 
dsLocations.EnforceConstraints = [/size][size=2][color=#0000ff]true[/color][/size][size=2];
 
 
 
DataView dv = dsLocations.SelectModele.DefaultView;
 
iFour = cmbFournisseur.SelectedIndex;
 
 
 cmbFournisseur.DataBind();
 
 
cmbModele.Enabled = cmbFournisseur.Enabled = cmbFournisseur.Items.Count != 0;
 
[/size][size=2][color=#0000ff]if[/color][/size][size=2]( cmbFournisseur.Items.Count > 0 )
 
{
 
 
 
dv.RowFilter = "[NoLessor]=" + cmbFournisseur.SelectedValue.ToString();
 
cmbModele.DataSource = dv;
 
cmbModele.DataMember = "NomModèle";
 
cmbModele.DataTextField = "NomModèle";
 
cmbModele.DataValueField = "NoModèle";
 
cmbModele.DataBind();
 
}
 
 
 
[/size][size=2][color=#0000ff]if[/color][/size][size=2]( [/size][size=2][color=#0000ff]this[/color][/size][size=2].IsPostBack )
 
{
 
cmbFournisseur.SelectedIndex = iFour;
 
 
 
cmbModele.DataSource = dv;
 
dv.RowFilter = "NoLessor=" + cmbFournisseur.SelectedValue.ToString();
 
cmbModele.DataMember = "NomModèle";
 
cmbModele.DataTextField = "NomModèle";
 
cmbModele.DataValueField = "NoModèle";
 
cmbModele.DataBind();
 
}
 
 
 
[/size][/size]


Because I have 1 dropdownlist that is sorted through the other. The cmbFournisseur set the content of cmbModele. But I want them to be selected correctly
 
Last edited:
OK! I solved my problem !

I put a variable before the DataBind that get the SelectedValue before is death (:))

If you have another solution that is more... effecient tell me !
 
Back
Top