c# - How do i compare a value to a multiple list items in a dropdownlist? -
I'm trying to make an argument here from where an item dropdown list from db will be present in the list menu. Is selected, and it will show a new item in a text box and "others" will be selected in the dropdown list.
This is what I have done so far
string gamdata = reedgame ["gTitle"]. ToString (); String gameTitle = ddlgameTile.Items.ToString (); If (printhouse data == gametitle) {ddlgameTile.SelectedIndex = ddlgameTile.Items.IndexOf (ddlgameTile.Items.FindByValue (gameData)); } Other {txtNewGame.Text = readGame ["gTitle"]. ToString (); DdlgameTile.SelectedIndex = ddlgameTile.Items.IndexOf (ddlgameTile.Items.FindByValue ("Other")); } I tried to use foreach loop and loop, it still will not work properly (okay). It only receives the second argument by the last list item which is "others"
Believe it If there is a gameData db item that you want to choose if it exists, you can use the item or null to get If it does not exist then you can set it to choose: selected string value = "other"; If (ddlgameTile.Items.FindByValue (gameData)! = Null) selectedValue = gameData; DdlgameTile.SelectedValue = selectedValue; However, if you have set the DataValueField and DataTextField , you should use the FindByText Will happen.
Comments
Post a Comment