Form fields auto population
Good day,
I hope you are all doing well. Please kindly help me, I need a way to auto fill my form will all the relevant data to the ID selected from the first text field. Once I select the ID in the first textbox then the other fields or textboxes shows the data corresponding to that ID.
Not Monitored
-
Michael Taylor 48,826 Reputation points
2022-09-22T14:27:04.087+00:00 Please provide us more information about what you're doing along with any relevant code. We don't understand what "form" you mean (Winforms? Form in a document?, form on a webpage?) We also don't understand what "select the ID in the first textbox" means. It sounds like you're trying to build a winforms form that allows the user to enter an ID and then you show the corresponding data in the remainder of the UI. But at this point we're just guessing.
Please use the
Code Sample
button to post the relevant code you currently have. -
Bonginkosi Nkambule 21 Reputation points
2022-09-22T14:58:18.257+00:00 Good day,
Apologies for that confusion caused.
"It sounds like you're trying to build a winforms form that allows the user to enter an ID and then you show the corresponding data in the remainder of the UI. But at this point we're just guessing." - Yes, this is exactly what I am talking about.
-
Michael Taylor 48,826 Reputation points
2022-09-22T15:21:42.68+00:00 Do you have any existing code you can share? There are several different ways to solve your problem but it depends on how you have built your app.
The simplest approach would be to query the data when the user clicks the "Submit" button. I'm assuming here that the user enters an ID and then clicks a button to retrieve the data. So your button handler would look the data up and then set the remaining controls on the form based upon the data returned.
private void button1_Clicked ( object sender, EventArgs e ) { //Get entered ID (ignoring error handling here...) var id = GetId(); var data = GetDataFromYourDatabase(id); if (data != null) //If we go the data { //Set UI _txtName.Text = data.Name; _txtDescription.Text = data.Description; }; }
If you want something more elaborate then you'll need to use data binding. For this you might look into using BindingSource. But if you don't need that advanced functionality then I'd keep it simple.
-
KristianSmith-MSFT 31 Reputation points • Microsoft Employee
2022-09-22T19:28:57.45+00:00 Hi BonginkosiNkambule-6299,
This openspecs tags handle requests related to Open Specifications documentation issues.
The Open Specifications can be found at: http://msdn.microsoft.com/en-us/library/cc203350.aspx.
Your question does not appear to be related to the Open Specifications documentation set, so I will remove the openspecs-office-fileformats tag. If you feel this is in error, please reference the document you would like assistance with, and add the tag back to your post.Thank you,
Kristian S
Support Escalation Engineer
Windows Protocols -
Bonginkosi Nkambule 21 Reputation points
2022-09-23T08:00:27.937+00:00 Good day,
The system is in PHP, below is the function code for the ID selection TextBox:
function fill_brand($conn){ $output = ''; $sql = "select * from tblemployees"; $result = mysqli_query($conn,$sql); while($row = mysqli_fetch_array($result)){ $output .= '<option value="'.$row["BS_Number"].'"> '.$row["BS_Number"].' </option>'; } return $output; }
-
Bonginkosi Nkambule 21 Reputation points
2022-09-23T08:01:43.763+00:00 Below is the ID selection TextBox:
<div class="col-md-4 col-sm-12"> <select id="emp_num" name="emp_num" class="custom-select form-control" required="true"> <option value=""> Select Employee Number </option> <?php echo fill_brand($conn); ?> </select> </div>
-
Bonginkosi Nkambule 21 Reputation points
2022-09-23T08:04:27.66+00:00 Below is the code for the function for the TextBoxes where I want to display the related information to the selected ID:
function fill_product($conn){ $output = ''; $sql = "select * from tblemployees"; $result = mysqli_query($conn,$sql); while($row = mysqli_fetch_array($result)){ $output .= '<option value="'.$row["FirstName"].'"> '.$row["FirstName"].' </option>'; } return $output; }
-
Bonginkosi Nkambule 21 Reputation points
2022-09-23T08:07:54.743+00:00 The below code is for the mouse click when selecting the ID:
if(isset($_POST["brand_id"])){ if($_POST["brand_id"] != ''){ $sql = "select * from tblemployees where emp_id = '".$_POST["brand_id"]."'"; }else{ $sql = "select * from tblemployees"; } $result = mysqli_query($conn,$result); while($row = mysqli_fetch_array($result)){ $output .= '<input name="emp_name" type="text" class="form-control date-picker" required="true" autocomplete="off" value="'.$row['FirstName'].'">'; } echo $output; }
-
Bonginkosi Nkambule 21 Reputation points
2022-09-23T08:11:39.783+00:00 Below is the code for displaying the name after the ID is selected:
<div class="col-md-4 col-sm-12" id="show_data"> <div class="form-group"> <?php echo fill_product($conn); ?> </div> </div>
Below is the Script
<script> $(document).ready(function(){ $('#emp_num').change(function(){ var brand_id = $(this).val(); $.ajax({ url:"add_contract.php", method:"POST", data:{brand_id:brand_id}, success:function(data){ $('#show_data').html(data); } }); }); }); </script>
EVERYTHING IS ON THE SAME PAGE
-
Michael Taylor 48,826 Reputation points
2022-09-23T13:59:23.127+00:00 PHP? What does this have to do with Winforms? You said you were using Winforms so PHP would not be applicable as that is for web development only.
If you're trying to get this to work in PHP then the MS forums is probably not where you should be posting your question.
-
Bonginkosi Nkambule 21 Reputation points
2022-09-23T14:07:30.073+00:00 THANK YOU!
Sign in to comment