set text box value to DB record

Results 1 to 2 of 2

Thread: set text box value to DB record

  1. #1
    Join Date
    Dec 1969

    Default set text box value to DB record

    I am setting the value of some form elements to the values of a single row returned by a db call like this<BR><BR> Dim strGoal1, strGoal2, strGoal3, strGoal4 As String<BR> Dim intRecCount, intWeight1, intWeight2, intWeight3, intWeight4, intAchieved1, intAchieved2, intAchieved3, intAchieved4 As Integer<BR> intRecCount = 0<BR> Do While objDataReader.Read<BR> strGoal1 = Trim(objDataReader("obj1_text"))<BR> strGoal2 = Trim(objDataReader("obj2_text"))<BR> strGoal3 = Trim(objDataReader("obj3_text"))<BR> strGoal4 = Trim(objDataReader("obj4_text"))<BR> intWeight1 = objDataReader("obj1_weight")<BR> intWeight2 = objDataReader("obj2_weight")<BR> intWeight3 = objDataReader("obj3_weight")<BR> intWeight4 = objDataReader("obj4_weight")<BR> intAchieved1 = objDataReader("obj1_actual")<BR> intAchieved2 = objDataReader("obj2_actual")<BR> intAchieved3 = objDataReader("obj3_actual")<BR> intAchieved4 = objDataReader("obj4_actual")<BR><BR> intRecCount = intRecCount + 1<BR> Loop<BR><BR> txtGoal1.Text = strGoal1<BR> txtGoal2.Text = strGoal2<BR> txtGoal3.Text = strGoal3<BR> txtGoal4.Text = strGoal4<BR> txtWeight1.Text = intWeight1<BR> txtAchieved1.Text = intAchieved1<BR> txtWeight2.Text = intWeight2<BR> txtAchieved2.Text = intAchieved2<BR> txtWeight3.Text = intWeight3<BR> txtAchieved3.Text = intAchieved3<BR> txtWeight4.Text = intWeight4<BR> txtAchieved4.Text = intAchieved4<BR><BR>This seems very manual and too similar to old school ASP<BR><BR>Is this the best way to do it - or is there a more efficient way<BR><BR>thanks

  2. #2
    Join Date
    Dec 1969

    Default DataValueField

    the textbox object, and other user controls for that matter, have properties that you can specify values for. in this case, i think you are looking for the DataValueField property, which you can set as follows:<BR>&#060;asp:textbox id="OrgNameTextBox" DataValueField = "Name" DataTextField = "Name" runat="server"/&#062;<BR><BR>in this case, "Name" is the name of the field in the dataset object, which was inherited from and is identical to the name in the underlying sql server database.<BR><BR>the code that populates it is as follows:<BR>Dim strOrgNameTextBox As String = tblOrgIDlabel.Rows(0)("Name")<BR>OrgNameTextBox.Te xt = strOrgNameTextBox<BR><BR>of course, these 2 lines come after some code that uses a sql statement to pull a single-line result-set from the data store. perhaps this is as long as your example, but it works, and it is what the articles i read taught me.<BR><BR>does this help? if it does, i would appreciate some help on the problem i am currently working on, which you can see at:<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts