How to dynamically generate a text field and collect data entered by the user?

I will be grateful for the answers in VB or C #

we use a database to create data collection forms with dynamic elements

enter image description here

I used this code to create labels and text fields from a table in a database (when the user clicks the "load CRF" button)

enter image description here

 Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim CRFgrid As New GridView
    CRFgrid.DataSource = CRFds
    CRFgrid.DataBind()

    Dim ItemCount As Integer = CRFgrid.Rows.Count
            Session("Itemcount") = CRFgrid.Rows.Count

    For I = 0 To (ItemCount - 1)
        Dim itemname As String = CRFgrid.Rows(0 + I).Cells(1).Text.ToString
        Session("Item") = "Item" + (I + 1).ToString
        Dim ItemNamelabel As New Label
        Dim ItemNameBox As New TextBox

        ItemNamelabel.ID = "L" + (I + 1).ToString
        Session("FU" + I.ToString) = ItemNamelabel.ID.ToString
        ItemNameBox.ID = "T" + (I + 1).ToString

        ItemNamelabel.Text = "<br />" + (Session("Item").ToString) + " " + itemname + " " + "<br />"

        Me.Form.Controls.Add(ItemNamelabel)
        Me.Form.Controls.Add(ItemNameBox)



    Next
End Sub

when the data collection form is loaded, the page looks like this:

enter image description here

and the "view page source" shows

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>

 </title></head>
<body>
<form method="post" action="Default.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"     value="/wEPDwUKLTI0NTA5MDI3NGRkUb8sl0uZpLbvUN/GSmHgjYxS9xqGR7rmcMBR3Ufhz4w=" />
</div>

<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWCQLf7PXOCQKM54rGBgK7q7GGCALF9vKRBQLs7+btDALs7+LtDALs797tDALs79rtDALs79btDDHrb+Vhkcph8brtCJP9//5IH57FFoImey2PApARP+k1" />

<input type="submit" name="Button1" value="LoadCRF" id="Button1" style="width:85px;" />
<br />
<br />
<input type="submit" name="Button2" value="InsertData" id="Button2" style="width:85px;" />
<br />
<br />

MRN
<input name="MRNtxt" type="text" id="MRNtxt" />
<br />
<br />
<span id="L1"><br />Item1 Diagnosis <br /></span><input name="T1" type="text" id="T1" /><span id="L2"><br />Item2 Treatment Protocol <br /></span><input name="T2" type="text" id="T2" /><span id="L3"><br />Item3 Initial CSF <br /></span><input name="T3" type="text" id="T3" /><span id="L4"><br />Item4 Location <br /></span><input name="T4" type="text" id="T4" /><span id="L5"><br />Item5 Consultant <br /></span><input name="T5" type="text" id="T5" /></form>

after the user fills out the form and click "Paste", I want to save the entered text in another tab in the database using this code. this does not work. Can you tell me where my mistake is?

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click


    Dim mydb As New OleDbConnection
    mydb =
    New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= |datadirectory|openclinica.mdb;Persist Security Info=True")
    mydb.Open()
    Dim Y As Integer = Session("Itemcount")
    For M = 1 To Y

        Session("FUt") = "L" + M.ToString
        Session("FUDt") = "T" + M.ToString

        Dim sqlstring = "INSERT INTO [Followup] ([MRN], [FU], [FUData]) VALUES (@MRNtxt, @" + Session("FUt") + ", @" + Session("FUDt") + ");"
        Dim mydbcommand As New OleDbCommand(sqlstring, mydb)
        mydbcommand.Parameters.Add("@MRNtxt", OleDbType.VarChar).Value = MRNtxt.Text
        mydbcommand.Parameters.Add("@" + Session("FUt"), OleDbType.VarChar).Value = Session("FUt").Text
        mydbcommand.Parameters.Add("@" + Session("FUDt"), OleDbType.VarChar).Value = Session("FUDt").Text
        mydbcommand.ExecuteNonQuery()

    Next

    mydb.Close()
End Sub

the error message looks like this when I click "paste"

enter image description here

+5
4

,

+2

, button1_click, , .

, , , , Page Init. . :

ASP.NET

- ,

, , , , CSS (display: none; visibility: hidden).

- , . :

: GridView ASP.NET 2.0

+2

... = Session("FUt").Text ... = Session("FUDt").Text.

, .Text , .

0

? Text ( , , , )?

0
source

All Articles