protected void SubmitNumberChoice_Click(object sender, EventArgs e) { //this is the submit button //to grab the contents of a control will DEPEND on the control access type //for TextBox, label, Literal use. Text //for list(RadioButton, DropdownList) you may use one of // .SelectedValue (best), SelectedIndev(physical location), SelectItem.Text //for Checkbox use Checked (boolean) //for the most part, all data from a control returns as a string //since the control (object) is on the "RIGHT" side of an assignment statement, // the object property uses its GET string submitchoice = NumberChoice.Text; if (string.IsNullOrEmpty(submitchoice)) { //"LEFT" side uses the property's SET MessageLabel.Text = "You did not enter a value for your program choice"; //clean up selection ChoiceList.ClearSelection(); //another way: //Choice.SelectedIndex = -1; //-1 is a non existent index CollectionChoiceList.SelectedIndex = 0; //has my prompt AlterLabel.ForeColor = System.Drawing.Color.Black; DisplayDataRO.Text = ""; } else { //"RIGHT" side uses the property's GET // you can set/get the radiobuttonlist choice by either using // .SelectedValue or .SelectedIndex or .SelctedItem.Text //it is BEST to use .SelectedValue for positioning ChoiceList.SelectedValue = submitchoice; //place a check mark in the check box, if the chosen course is a program if (submitchoice.Equals("2") || submitchoice.Equals("4")) { ProgrammingCourseActive.Checked = true; AlterLabel.ForeColor = System.Drawing.Color.BlueViolet; } else { ProgrammingCourseActive.Checked = false; AlterLabel.ForeColor = System.Drawing.Color.Black; } //DDL can be positioned using: // .SelectedValue or .SelectedIndex or .SelctedItem.Text //it is BEST to use .SelectedValue for positioning CollectionChoiceList.SelectedValue = submitchoice; //demonstration of what is obtaine by the different .Selectedxxxxxx DisplayDataRO.Text = CollectionChoiceList.SelectedItem.Text + " at index " + CollectionChoiceList.SelectedIndex + " having a value of " + CollectionChoiceList.SelectedValue; } }
protected void ResetFields() { NumberChoice.Text = ""; ChoiceList.ClearSelection(); //ChoiceList.SelectedIndex = -1; //index -1 will not be found, optionally way CollectionChoiceList.ClearSelection(); ProgrammingCourseActive.Checked = false; AlterLabel.ForeColor = System.Drawing.Color.Black; }
protected void ResetFields() { DisplayDataRO.Text = ""; ProgrammingCourseActive.Checked = false; ChoiceList.ClearSelection(); //ChoiceList.SelectedIndex = -1; //This is an optional way of deselecting CollectionChoiceList.ClearSelection(); AlterLabel.ForeColor = System.Drawing.Color.Black; }
protected void SubmitNumberChoice_Click(object sender, EventArgs e) { //to grab the contents of a control will DEPEND on the cntrol access type // for TextBox, label, or literal use .text // for List (RadiobuttonList, DropDownList) you may use one of: // .SelectedValue(best), .SelectedIndex(phyical location), .SelectedItem.Text // for CheckBox use .Checked (boolean) //for the most part, all data from a control returns as a string //since the control (object) is on the "right" side of an assignment (set;), statement, the object Property uses its (get;) string submitchoice = NumberChoice.Text; if (string.IsNullOrEmpty(submitchoice)) { //"left" side uses the Property's SET MessageLabel.Text = "You did not enter a value for your program choice"; ChoiceList.ClearSelection(); //ChoiceList.SelectedIndex = -1; //-1 is a non-existent index. similar, but not necessary //CollectionChoiceList.ClearSelection(); CollectionChoiceList.SelectedIndex = 0; //0 has my prompt AlterLabel.ForeColor = System.Drawing.Color.Black; DisplayDataRO.Text = ""; } else { // you can set/get the radiobuttonlist choice by either using // .SelectedValue or .SelectedIndex or SelectedItem.Text // it is BEST to use .SelectedValue for positioning (go an find the line with the proper value and display as desired) // using .SelectedIndex requires you know the exact physical location ChoiceList.SelectedValue = submitchoice; if (submitchoice.Equals("2") || submitchoice.Equals("4")) { ProgrammingCourseActive.Checked = true; AlterLabel.ForeColor = System.Drawing.Color.AliceBlue; } else { ProgrammingCourseActive.Checked = false; AlterLabel.ForeColor = System.Drawing.Color.Black; } //DDL an be positioned using // .SelectedValue or .SelectedIndex or SelectedItem.Text // it is BEST to use .SelectedValue for positioning CollectionChoiceList.SelectedValue = submitchoice; //demonstration of what is obtained by the different by the .SelectedIndex or SelectedItem.Text DisplayDataRO.Text = CollectionChoiceList.SelectedItem.Text + " at index " + CollectionChoiceList.SelectedIndex + " having a value of " + CollectionChoiceList.SelectedValue; } }