Home > OS >  how to fill textboxes on a web page
how to fill textboxes on a web page

Time:11-09

the web page is a public page and it is not created by me. there are about 20 textboxes and I want to fill them with specific data with one click. any idea about how to do this ?

ps. I worked with asp.net and c# years back and now I don't remember much. but a hint should be enough, although if you guide completely I would be appreciate.

ps2. it seems that I should write the code into a windows application I guess.

CodePudding user response:

If you can settle for javascript/typescript, enter image description here

On the other hand, if I use this sql

        string strSQL = "SELECT TOP 4 * FROM tblHotels ORDER by HotelName";

Then I now get this:

enter image description here

So, as you can see, it no more work to display 1, or 20 of that "thing" I repeated. And I could say have the repeating go accross the page, and I now have a card-view like system.

You can of course also just write code, and shove the values into textboxes. So without say a repeater control, and just he text boxes, then this would work:

        string strSQL = "SELECT * FROM tblHotels ORDER by HotelName";
        using (SqlCommand cmdSQL = new SqlCommand(strSQL,
                             new SqlConnection(Properties.Settings.Default.TEST4)))
        {
            DataTable rstData = new DataTable();
    
            cmdSQL.Connection.Open();
            rstData.Load(cmdSQL.ExecuteReader());

            DataRow OneRow = rstData.Rows[0];

            txtHotelName.Text = OneRow["HotelName"].ToString();
            txtFirst.Text = OneRow["FirstName"].ToString();
            txtLast.Text = OneRow["LastName"].ToString();
            txtCity.Text = OneRow["City"].ToString();
            chkActive.Checked = (bool)OneRow["Active"];
            
        }

so you have a lot of options here. And for sure, one will often introudce a model framework (like older datasets, or now EF (entity framework). This gives you a model in code, and thus often you don't have remember the field names, and you get/have a abstracted layer between you and the database.

And most of the data repeating controls are happy to use EF data, or even direct data tables like above shows.

  • Related