Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Preselect a value in a DropDown list
Message
De
28/07/2003 14:35:42
 
 
À
28/07/2003 10:56:21
Jerry Tovar
Dana Corporation Dana It
Maumee, Ohio, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00814120
Message ID:
00814256
Vues:
9
Jerry,

We set up properties in our drop down list class for specifying the Bound table, column and row and an EventHandler for the DataBind event. Then, in that EventHandler, you can do something like this:
string value = this.SelectedValue;
if (this.BoundTable != null && this.BoundTable.Rows.Count > this.BoundRow)
    value = this.BoundTable[this.BoundRow][this.BoundColumn].ToString();
else
{
    this.SelectedIndex = 0;
    return;
}

try
{
    this.SelectedValue = value;
}
catch (Exception ex)
{
}
HTH,
~~Bonnie


>I'm using ASP.Net to create a Webform. My Webform contains a State drop down list. I populate the drop down with values from my state.dbf table.
>
>The Webform is an editing form that allows you to modify an employee's information. How can I preselect the correct state in the drop down list based on the current employee's state value?
>
>The SelectedIndex works if you know the row, but what if you only know the character value such as 'OH'?
>
>Here's how I populate the state drop down:
>
>this.cbo_loc.DataTextField = "cstate";  //From state.dbf.
>this.cbo_loc.DataValueField = "cstate"; //From state.dbf.
>this.cbo_loc.DataSource = myDS;
>//this.cbo_loc.SelectedIndex = 2;  //This will work but I only know the char value.
>this.cbo_loc.DataBind();
>
>
>Thanks,
>
>Jerry
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform