skip to Main Content

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.

2

Answers


  1. If you can settle for javascript/typescript, https://testcafe.io/ might achieve your goal.

    Login or Signup to reply.
  2. Well, it depends. Often to display data, I will drop in say a repeater, or say a datalist control.

    I even use the wizard to create the control with the fields, and then DELETE say the data source that the wizard created.

    So, say we have this markup:

    <asp:Repeater ID="Repeater1" runat="server">
        <ItemTemplate>
            <div style="border-style:solid;color:black;width:300px;float:left">
            <div style="padding:5px;text-align:right">
    
                Hotel Name: 
                <asp:TextBox ID="txtHotelName" runat="server" Text ='<%# Eval("HotelName") %>' />
                <br />                                                                                             
                First Name:
                <asp:TextBox ID="txtFirst" runat="server" Text ='<%# Eval("FirstName") %>' />
                <br />                                                                                             
                Last Name:
                <asp:TextBox ID="txtLast" runat="server" Text ='<%# Eval("LastName") %>'  />
                <br />                                                                                             
                City:
                <asp:TextBox ID="txtCity" runat="server" Text ='<%# Eval("City") %>'  />
                <br />
                Active:
                <asp:CheckBox ID="chkActive" runat="server" Checked = '<%# Eval("Active") %>'/>
    
                <asp:HiddenField ID="PK" runat="server" Value = '<%# Eval("ID") %>'/>
                
                <asp:Button ID="cmdDelete" runat="server" Text="Delete" style="margin-left:20px"                     
                   OnClick="cmdDelete_Click"/>
            </div>
        </div>
         <div style="clear:both;height:4px"></div>
        </ItemTemplate>
     </asp:Repeater>
    

    No, not 20 fields, but if I used the wizard to select all 20 columns during creating, I would at least not have to type out the above – but only "tweak" it after using the wizard to create that repeater, or datalist.

    Ok, so now the code to fill the above.

    It looks like this:

       protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }
    
        public void LoadData()
        {
            string strSQL = "SELECT * FROM tblHotels WHERE ID = 23 ORDER BY HotelName";
    
            using (SqlCommand cmdSQL = new SqlCommand(strSQL,
                                 new SqlConnection(Properties.Settings.Default.TEST4)))
            {
                cmdSQL.Connection.Open();
                Repeater1.DataSource = cmdSQL.ExecuteReader();
                Repeater1.DataBind();
            }
        }
    

    And we now see this:

    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 across 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 introduce 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search