Click here to Skip to main content
15,899,475 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a web form that populates data from the database. That part works fine. I have a database that has a User ID and different Unit IDs. I know I could just make a Grid View to display all of the data just for that user but I wanted to know if there is a way to do it to a textbox?

Example:
XML
USER | Unit ID | Car | Truck |
100  | 200     |  1  |   2   |
100  | 300     |  3  |   4   |
100  | 400     |  6  |   7   |


How can this data be populated into textboxes?

Here is the current code I use to populate textboxes:
C#
if (TextBoxINST_ID.Text.Trim().Length > 0)
            {
                SqlConnection con3 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
                con3.Open();

                SqlCommand scmd3 = new SqlCommand("Select FT_UNDERGR, FT_GRAD, FTE_UNDERG, FTE_GRAD, NON_CREDIT, TOTAL_FTE, FCFTUHC, FCFTPBHC, FCPTUHC, FCPTPBHC, NCHC, FTE40, HC50, FTE4050, UnderG12, Postb9, Total123b4b, THCAS from Table88 where User_ID = '" + TextBoxUser_ID.Text + "'", con3);
                SqlDataReader dr3 = scmd3.ExecuteReader();
                if (dr3.Read())
                {
                    TextBoxFTUG2.Text = dr3["FT_UNDERGR"].ToString();
                    TextBoxFTG2.Text = dr3["FT_GRAD"].ToString();
                    TextBoxTHUGDR2.Text = dr3["FTE_UNDERG"].ToString();
                    TextBoxTHGDR2.Text = dr3["FTE_GRAD"].ToString();
                    TextBoxNCCDR2.Text = dr3["NON_CREDIT"].ToString();
                    TextBoxTCNC2.Text = dr3["TOTAL_FTE"].ToString();
                    TextBoxTNFUG2.Text = dr3["FCFTUHC"].ToString();
                    TextBoxTNFG2.Text = dr3["FCFTPBHC"].ToString();
                    TextBoxTNCPUG2.Text = dr3["FCPTUHC"].ToString();
                    TextBoxTNCPG2.Text = dr3["FCPTPBHC"].ToString();
                    TextBoxTNNCC2.Text = dr3["NCHC"].ToString();
                    TextBoxFTE402.Text = dr3["FTE40"].ToString();
                    TextBoxHC502.Text = dr3["HC50"].ToString();
                    TextBoxFTE40502.Text = dr3["FTE4050"].ToString();
                    TextBoxTHUG2.Text = dr3["UnderG12"].ToString();
                    TextBoxTHG2.Text = dr3["Postb9"].ToString();
                    TextBoxT12342.Text = dr3["Total123b4b"].ToString();
                    TextBoxTHCAS2.Text = dr3["THCAS"].ToString();
                    ButtonSubmit2.Visible = true;

                }
                con3.Close();
                dr3.Close();
Posted
Updated 29-Oct-14 4:26am
v3
Comments
Dilan Shaminda 29-Oct-14 9:40am    
you want to put one row of data to textboxes or all the records into texboxes?
Computer Wiz99 29-Oct-14 9:45am    
All the records into different textboxes. Example:
If there is a record that matches User ID 100 and the Unit ID is 200, all of the data in that record should populate into one set of textboxes. Right now I have 5 sets of textboxes to populate 5 records that match User ID 100.

Can you follow me?
Computer Wiz99 29-Oct-14 10:13am    
I can populate textboxes from a database without the Unit Id but since the Unit ID and the User ID are connected, How can I populate multiple textboxes if the Unit Id is different for that user?
Computer Wiz99 29-Oct-14 10:27am    
I have updated my code.
Dilan Shaminda 29-Oct-14 11:38am    
as solution 1 suggested you can create custom controller of textboxes for a row

http://www.codeproject.com/Articles/28783/Your-First-ASP-NET-Custom-Control
http://msdn.microsoft.com/en-us/library/zt27tfhy(v=vs.100).aspx

1 solution

Seriously? I wouldn't, I'd use a Gridview, or an HTML table.

The other solution (which at least makes things tidier) would be to create a custom control which contains the appropriate number of textboxes for a row, and dynamically create one of those for each row.

But I'd go with the GridView.
 
Share this answer
 
Comments
Computer Wiz99 29-Oct-14 11:57am    
If I do it in a Grid View, how can I get those values from the Grid View to the another database when the user clicks Submit button?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900