Datasets and Textboxes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JLC
    New Member
    • Sep 2006
    • 34

    Datasets and Textboxes

    Hi,
    I have a dropdown list that I have populated with a dataset.

    Code:
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataService.DataService myData = new DataService.DataService();
                DataSet domainData = myData.GetDomainData();
    
                StatusDropDownList.DataSource = domainData.Tables[0];
                
                StatusDropDownList.DataTextField = "Name";
                StatusDropDownList.DataValueField = "ID";
                
                StatusTextBox.Text = <-- have problem here...
    
                //Bind the data to the control
                StatusDropDownList.DataBind();
    
                //set default selected item
                StatusDropDownList.SelectedIndex = 0;
            }
        }
    When I load the page I want the "Detail" column in the dataset to be displayed in the text box. So if the drop down list says "down", then the text box would have text that is in the dataset that corresponds to that selection.

    I will work out the part about when a user changes that selection, the text will change, but I can't seem to populate the textbox when the page loads.

    Thanks,
    JLC
  • nateraaaa
    Recognized Expert Contributor
    • May 2007
    • 664

    #2
    Originally posted by JLC
    Hi,
    I have a dropdown list that I have populated with a dataset.

    Code:
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataService.DataService myData = new DataService.DataService();
                DataSet domainData = myData.GetDomainData();
    
                StatusDropDownList.DataSource = domainData.Tables[0];
                
                StatusDropDownList.DataTextField = "Name";
                StatusDropDownList.DataValueField = "ID";
                
                StatusTextBox.Text = <-- have problem here...
    
                //Bind the data to the control
                StatusDropDownList.DataBind();
    
                //set default selected item
                StatusDropDownList.SelectedIndex = 0;
            }
        }
    When I load the page I want the "Detail" column in the dataset to be displayed in the text box. So if the drop down list says "down", then the text box would have text that is in the dataset that corresponds to that selection.

    I will work out the part about when a user changes that selection, the text will change, but I can't seem to populate the textbox when the page loads.

    Thanks,
    JLC
    Code:
    protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataService.DataService myData = new DataService.DataService();
                DataSet domainData = myData.GetDomainData();
    
                StatusDropDownList.DataSource = domainData.Tables[0];
                
                StatusDropDownList.DataTextField = "Name";
                StatusDropDownList.DataValueField = "ID";            
                
                //Bind the data to the control
                StatusDropDownList.DataBind();
    
                //set default selected item
                StatusDropDownList.SelectedIndex = 0;            
            }
               CREATE A CASE STATEMENT FOR EVERY SELECTED INDEX
                 switch(StatusDropDownList.SelectedIndex)
                   case: 0
                        StatusTextBox.Text = //Detail column you want to display
                   break;
                   default:
                        StatusTextBox.Text = "";
                   break;
        }
    Nathan

    Comment

    • JLC
      New Member
      • Sep 2006
      • 34

      #3
      So if the list of values in the drop down list is created from the dataset, can't I just pull out the value I want from the dataset to populate the text box instead of creating a switch statement?

      does asp:dropdownlis t have another place I could store a string (which would come from my dataset) so I could use it in my text box?

      Thanks,

      Comment

      Working...