andywhat
asked on
Populating textbox from returned stored procedure values
I have a small app that I need to finish, this is being done in web developer express 2008. I have so far created a gridview that loads the customer's data. That gridview is done through code (databind) first part of code. Then when the "Edit" command is clicked what I would like is the textboxes corresponding to each field of that gridview to be loaded with the returned values of the corresponding stored procedure. Any help would be greatly appreciated.
Function loadGrid(ByRef spname As String, ByRef gvName As GridView)
Dim ConnString As String
'The SQL Connection
ConnString = "Data Source=HOME\SQLEXPRESS;Initial Catalog=Mobi;Integrated Security=SSPI;"
'Set the Connection String
Dim SQLConn As New SqlConnection(ConnString)
Dim SQLCmd As New SqlCommand(spname, SQLConn) 'The SQL Command
SQLCmd.CommandType = CommandType.StoredProcedure
Try
SQLConn.Open() 'Open the connection
SQLCmd.Connection = SQLConn 'Sets the Connection to use with the SQL Command
SQLCmd.ExecuteNonQuery() 'Executes SQL Commands Non-Querys only
gvName.DataSource = SQLCmd.ExecuteReader()
gvName.DataBind()
Catch ex As Exception
lblMessage.Text = "Could not load data" + ex.Message
Finally
SQLConn.Close()
End Try
End Function
'load text
Function loadtext(ByRef spName As String)
Dim daMyName As SqlDataAdapter
Dim dsMyName As DataSet
Dim ConnString As String
'The SQL Connection
ConnString = "Data Source=HOME\SQLEXPRESS;Initial Catalog=Mobi;Integrated Security=SSPI;"
'Set the Connection String
Dim SQLConn As New SqlConnection(ConnString)
Dim SQLCmd As New SqlCommand(spName, SQLConn) 'The SQL Command
SQLCmd.CommandType = CommandType.StoredProcedure
Try
SQLConn.Open() 'Open the connection
SQLCmd.Connection = SQLConn 'Sets the Connection to use with the SQL Command
daMyName.SelectCommand = SQLCmd
daMyName.Fill(dsMyName)
Me.txtFirstName.Text = dsMyName.Tables(0).Rows(0).Item("First Name").ToString
Me.txtLastName.Text = dsMyName.Tables(0).Rows(1).Item("Last Name").ToString
Me.txtPhoneNumber.Text = dsMyName.Tables(0).Rows(2).Item("Phone").ToString
Me.txtEmail.Text = dsMyName.Tables(0).Rows(3).Item("Email").ToString
Me.txtDOB.Text = dsMyName.Tables(0).Rows(4).Item("DOB").ToString
Me.txtAddress.Text = dsMyName.Tables(0).Rows(5).Item("Address").ToString
Me.txtCity.Text = dsMyName.Tables(0).Rows(6).Item("City").ToString
Me.ddlState.SelectedValue = dsMyName.Tables(7).Rows(0).Item("State").ToString
Me.txtZip.Text = dsMyName.Tables(0).Rows(8).Item("Zip").ToString
Me.txtHeight.Text = dsMyName.Tables(0).Rows(9).Item("Height").ToString
Me.txtWeight.Text = dsMyName.Tables(0).Rows(10).Item("Weight").ToString
Me.ddlGender.SelectedValue = dsMyName.Tables(0).Rows(11).Item("Gender").ToString
' Me.txtMedicare.Text = dsMyName.Tables(0).Rows(0).Item("Medicare").ToString
'Me.txtMedicareType.Text = dsMyName.Tables(0).Rows(0).Item("MedicareType").ToString
'Me.ddlInsuranceType.SelectedValue = dsMyName.Tables(0).Rows(0).Item("InsuranceType").ToString
' Me.txtMedicaid.Text = dsMyName.Tables(0).Rows(0).Item("Medicaid").ToString
Me.txtNotes.Text = dsMyName.Tables(0).Rows(16).Item("Notes").ToString
Catch ex As Exception
lblMessage.Text = "Could not load data" + ex.Message
Finally
SQLConn.Close()
End Try
End Function
right above your text that you want populated you need to reference your text box, like object.textbox1 or whatever you have it named.
ASKER
HDSportster08:
If you are referring to the actual textbox it is created in the aspx page, the control is there. I am referencing the control in the vb file.
This is a sample of what I have in the aspx page:
If you are referring to the actual textbox it is created in the aspx page, the control is there. I am referencing the control in the vb file.
This is a sample of what I have in the aspx page:
<div class="title">
Personal Information:
</div>
<table>
<tr>
<td>
First Name:
</td>
<td>
<asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Last Name:
</td>
<td>
<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Phone Number:
</td>
<td>
<asp:TextBox ID="txtPhoneNumber" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Email:
</td>
<td>
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Date of Birth:
</td>
<td>
<asp:TextBox ID="txtDOB" runat="server" Text="MM/DD/YYYY"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Address:
</td>
<td>
<asp:TextBox ID="txtAddress" runat="server" Width="204px"></asp:TextBox>
</td>
<td>
City:
</td>
<td>
<asp:TextBox ID="txtCity" runat="server" Width="131px"></asp:TextBox>
</td>
<td>
State:
</td>
<td>
<asp:DropDownList ID="ddlState" runat="server" Width="44px">
</asp:DropDownList>
</td>
<td>
Zip:
</td>
<td>
<asp:TextBox ID="txtZip" runat="server" Width="80px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Height:
</td>
<td>
<asp:TextBox ID="txtHeight" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Weight:
</td>
<td>
<asp:TextBox ID="txtWeight" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
so you would need something like this right?
Here is the coding;
<asp:TemplateColumn HeaderText="Data Entry">
<ItemTemplate>
<img src="images/Barrow.gif" onclick="CopyTotal(this);" title="Click here to
copy Previous Field to this text box">
<asp:TextBox CssClass="printableTextbox" runat="server"
onchange="AddRequesterName(this);" Readonly='<% #
iif(Container.DataItem("NotAllowed")=1,True,False) %>' id="txtDataEntry"
Text='<% # Format(Container.DataItem("Data"),"$#,##0.00") %>'
onblur="this.value=FormatCurrency(this.value,1);">
</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
ASKER
I believe that code is for a gridview item, this is regular textboxes that I am trying to fill with data
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Great to hear you figured it out. This stuff is hard to me as well.