Showing posts with label textbox. Show all posts
Showing posts with label textbox. Show all posts

Monday, March 26, 2012

Populate a ListBox based on database search

I am trying to populate a ListBox with values retrieved from a database based on a search. I have a TextBox in which the user will enter the text they wish to search for, a Button which will submit the text, and then a ListBox which is invisible until values are returned from the database. I have a SqlDataSource with a SelectCommand saying "SELECT * FROM [table] WHERE [name] LIKE '@dotnet.itags.org.Parameter'". I want to know how to bind the value in the TextBox to the "@dotnet.itags.org.Parameter" in the Sql statement. I am quite new at programming, and I'm sure this is quite a simple task. Any help would be appreciated.

MYSQL:

myCommand.Parameters.Clear();
myCommand.CommandText = "SELECT * FROM [table] WHERE [name] LIKE (?)";
myCommand.Parameters.Add(new OdbcParameter(null, txtSearch.Text));

MSSQL:

myCommand.Parameters.Clear();
myCommand.CommandText = "SELECT * FROM [table] WHERE [name] LIKE @.search";
myCommand.Parameters.Add(new SqlParameter("@.search", txtSearch.Text));


Thanks for the reply. Where would I put this code? I'm using MSSql, but I am not using any stored procedures. All my SQL code is on my .aspx page. Should this go somewhere on my .aspx page or in my VB codebehind?

This would go in your code behind, in the onclick method from your button (double click your submit button and you'll go automatically to your onclick method).

Remember the code I gave in the example is C# code, I don't know the correct syntax in VB.net but it should get you started.


This should help:

http://www.asp.net/learn/dataaccess/default.aspx?tabid=63

Cheers

Populate a Password Textbox from DB

Hello,

I have a query that populates several textboxes on my page.

I have a textbox called tboxPassword and it's type is set to password.

The the query runs, the Password box is left empty. I'm assuming this is some feature of the 'password' type assigned to the box. Is there anyway to overcome this? It's ok if the password still appears as ****, but I'd like it to be in the boxes.

Thanks!
Jason<input type="password" value="PASSWORDHERE" /
<asp:textbox TextMode="password" text="blahblahblah" runat="server" /
In either case, the password will appear as ****, but the underlying HTML (viewable through a simple "View Source") will show the password in plain text. In otherwords, you lose any and all password security by doing this and you shouldnot do it.
Actually, you cannot populate a password textbox from code. Even if you try to assign it a value, hoping it will appear as ****, it will not work.

As pickyh3d said, you shouldn't want to do this.

You can't do it anyway.
heh woops. I never tried it, so I just figured it would work... you could cheat and hard code it into an input tag, but you still shouldn't.

Learn something new everyday.

Saturday, March 24, 2012

populate textbox

how can we populate a textbox using information from database, using asp.net
and c#You can find an example of this here:
http://www.developerfusion.com/show/4410/5/
Chris
--
>From: sqlprob@.yahoo.fr (Celine)
>Newsgroups: microsoft.public.dotnet.framework.aspnet
>Subject: populate textbox
>Date: 5 Apr 2004 14:12:31 -0700
>Organization: http://groups.google.com
>Lines: 1
>Message-ID: <f34b6b7.0404051312.49dd3677@.posting.google.com>
>NNTP-Posting-Host: 62.254.64.8
>Content-Type: text/plain; charset=ISO-8859-1
>Content-Transfer-Encoding: 8bit
>X-Trace: posting.google.com 1081199551 16666 127.0.0.1 (5 Apr 2004
21:12:31 GMT)
>X-Complaints-To: groups-abuse@.google.com
>NNTP-Posting-Date: Mon, 5 Apr 2004 21:12:31 +0000 (UTC)
>Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.s
ul.t-online.de!t-online.de!news.glorb.com!postnews1.google.com!not-for-mail
>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:223743
>X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
>how can we populate a textbox using information from database, using
asp.net and c#
>

populate textbox

how can we populate a textbox using information from database, using asp.net and c#You can find an example of this here:
http://www.developerfusion.com/show/4410/5/

Chris
-------
>From: sqlprob@.yahoo.fr (Celine)
>Newsgroups: microsoft.public.dotnet.framework.aspnet
>Subject: populate textbox
>Date: 5 Apr 2004 14:12:31 -0700
>Organization: http://groups.google.com
>Lines: 1
>Message-ID: <f34b6b7.0404051312.49dd3677@.posting.google.com>
>NNTP-Posting-Host: 62.254.64.8
>Content-Type: text/plain; charset=ISO-8859-1
>Content-Transfer-Encoding: 8bit
>X-Trace: posting.google.com 1081199551 16666 127.0.0.1 (5 Apr 2004
21:12:31 GMT)
>X-Complaints-To: groups-abuse@.google.com
>NNTP-Posting-Date: Mon, 5 Apr 2004 21:12:31 +0000 (UTC)
>Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFT NGP08.phx.gbl!newsfeed00.s
ul.t-online.de!t-online.de!news.glorb.com!postnews1.google.com!not-for-mail
>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:223743
>X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
>how can we populate a textbox using information from database, using
asp.net and c#
You can find an example of this here:
http://www.developerfusion.com/show/4410/5/

Chris
-------
>From: sqlprob@.yahoo.fr (Celine)
>Newsgroups: microsoft.public.dotnet.framework.aspnet
>Subject: populate textbox
>Date: 5 Apr 2004 14:12:31 -0700
>Organization: http://groups.google.com
>Lines: 1
>Message-ID: <f34b6b7.0404051312.49dd3677@.posting.google.com>
>NNTP-Posting-Host: 62.254.64.8
>Content-Type: text/plain; charset=ISO-8859-1
>Content-Transfer-Encoding: 8bit
>X-Trace: posting.google.com 1081199551 16666 127.0.0.1 (5 Apr 2004
21:12:31 GMT)
>X-Complaints-To: groups-abuse@.google.com
>NNTP-Posting-Date: Mon, 5 Apr 2004 21:12:31 +0000 (UTC)
>Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFT NGP08.phx.gbl!newsfeed00.s
ul.t-online.de!t-online.de!news.glorb.com!postnews1.google.com!not-for-mail
>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:223743
>X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
>how can we populate a textbox using information from database, using
asp.net and c#

populate textbox

how can we populate a textbox using information from database, using asp.net and c#You can find an example of this here:
http://www.developerfusion.com/show/4410/5/

Chris
-------
>From: sqlprob@.yahoo.fr (Celine)
>Newsgroups: microsoft.public.dotnet.framework.aspnet
>Subject: populate textbox
>Date: 5 Apr 2004 14:12:31 -0700
>Organization: http://groups.google.com
>Lines: 1
>Message-ID: <f34b6b7.0404051312.49dd3677@.posting.google.com>
>NNTP-Posting-Host: 62.254.64.8
>Content-Type: text/plain; charset=ISO-8859-1
>Content-Transfer-Encoding: 8bit
>X-Trace: posting.google.com 1081199551 16666 127.0.0.1 (5 Apr 2004
21:12:31 GMT)
>X-Complaints-To: groups-abuse@.google.com
>NNTP-Posting-Date: Mon, 5 Apr 2004 21:12:31 +0000 (UTC)
>Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFT NGP08.phx.gbl!newsfeed00.s
ul.t-online.de!t-online.de!news.glorb.com!postnews1.google.com!not-for-mail
>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:223743
>X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
>how can we populate a textbox using information from database, using
asp.net and c#

Populate textbox from item selected in a drop down list

I am a newbie to .net so bear with me here.

I have a page that has a dropdown list of customers. I want to select a customer from that dropdown and populate the appropriate textboxes.

So when I select 'John Smith' from the dropdown list I have a form with textboxes for first name, last name, accout id, etc that needs to populate accordingly. I am using VB.net with MS SQL. I have been successful populating the dropdown list from the DB. Where I am lost is populating the appropriate textboxes for the customer selected in the dropdown list. Any help is appreciated.Hi,

If you are having the dropdownlist and the textbox in the same form, then you need to do as below:-

Set the autopostback property for the dropdownlist to true. This will make the dropdownlist post back to the server, once an element is selected. Then, you can put the following code in your codebehind file to get the selected item.

If Not IsPostBack Then

textbox1.text = dropdownlist1.SelectedItem.Text

End If

If you are having the textbox in a different form, then you need to pass the selected value by querystring to that form.

If Not IsPostBack Then

Response.Redirect("NewForm.aspx?name=" & dropdownlist1.SelectedItem.Text)

End If

Then in the new form, you can get the value using the following code:-

textbox1.text = Request.Params("name")

Hope it helps.
Something to keep in mind:

The name of the user (or whatever) may not be unique. You can have two people with the name "John Smith." You propably have a column in your DB that is unique for each person like UserID or whatever.

So when you update the dropdownlist from the database, you need to retrieve the unique id for each person as well, so that when the index of the selected index in the drop down list changes, you can use the corresponding unique ID to retrieve the other info from the database.

I cant remember exactly, but you should take a loot at the dropdown control itself. Many such controls have a 'Value' for each item in them. You van set the 'Value' to the unique ID somehow.

Youll have to take a look...

Wednesday, March 21, 2012

Populate textbox with textmode=password

I'm trying to populate a password style text box from information in a database. It will populate when I change it to a singleline text (or normal) but it will not with a password style. I would like it to populate with the ******* but be able to have the actual data in the background so I can submit it to a database.

ThanksWrite a code behind for this for text change event to change to * from test..

Nor text box has a property of password...

Cheers,
Devendra Naik
It's be design.. but there is a way around it.. instead of changing the Text property, you can do this:


myTextBox.Attributes["value"] = "somethingfromthedatabase";

Populate textbox with dropdown selection (in Wizard Control), using javascript

I have a Wizard Control that contains a number of controls:

After the user selects an item from a DropDown, and the control has lostfocus, I need the selected value to pre-populate a TextBox usingjavascript.

If I create a 'new website' and just throw a dropdown list and textbox onto the page the following code works perfectly:

** Default.aspx.vb:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
DropDownList1.Attributes.Add("onblur", "FillTextbox()")
End Sub

** Default.aspx:

function FillTextbox ()
{
document.getElementById("TextBox1").value=document.getElementById("DropDownList1").value;
}

The above code, however DOESN'T work if the controls are embedded in a wizard control.

Thus, my question is: How do I get the code to work if the DropDown and TextBox controls are in a Wizard Control?

Any help would be much appreciated!

I believe when the control is embedded within another control the actual name that ends up being used includes the parent-control's name, e.g. Parent_mycontrol. Take a look at the source (right click, View Source) when you run the page to find the actual name of the control. You can reference it by that name in your javascript, fillTextbox() function.

Good luck.


You need to find the correct ID for the TextBox control. As suggested by the fellow developer you need to use the View Source and find the correct ID for the TextBox control. Once, you find the correct ID simply use that Id in the javascript function.

Thank you both SO MUCH for your help! That worked like a charm!Big Smile

Populate TextBox With DB Records

This function in a VB class file takes UserID as a parameter & returns
a SqlDataReader to the calling function which exists in a ASPX page:
Namespace NConnect
Public Class Cart
Private sqlConn As New SqlConnection("....")
Public Function GetAddress(ByVal UserID As Integer) As
SqlDataReader
Dim sqlCmd As SqlCommand
Dim sqlReader As SqlDataReader
sqlCmd = New SqlCommand("NETGetAddress", sqlConn)
sqlCmd.CommandType = CommandType.StoredProcedure
Try
With sqlCmd
.Parameters.Add("@dotnet.itags.org.UserID", SqlDbType.Int).Value =
UserID
End With
sqlConn.Open()
sqlReader = sqlCmd.ExecuteReader
Catch ex As Exception
Throw ex
End Try
Return sqlReader
End Function
End Class
End Namespace
Using vbc, I successfully compiled the above class file into a DLL
named NConnect.dll.
This is the simple stored procedure:
CREATE PROCEDURE NETGetAddress
@dotnet.itags.org.UserID integer
AS
SELECT UserID, Address, City, State, Country, Zip FROM tblUsers WHERE
UserID = @dotnet.itags.org.UserID
The ASPX page uses a user control named 'Address.ascx' which has 5
TextBoxes named txtAddress, txtCity, txtState, txtCountry & txtZip. I
am using the Get & Set statement for creating a property for each of
the TextBoxes like this:
Public Property Address() As String
Get
Address = txtAddress.Text
End Get
Set(ByVal value As String)
txtAddress.Text = value
End Set
End Property
'here comes the other properties
Finally, this is the ASPX page:
<%@dotnet.itags.org. Register TagPrefix="NETConnect" TagName="Address"
Src="NETAddress.ascx" %>
<%@dotnet.itags.org. Import Namespace="NConnect" %>
<%@dotnet.itags.org. Import Namespace="System.Data" %>
<%@dotnet.itags.org. Import Namespace="System.Data.SqlClient" %>
<script runat="server">
Sub Page_Load(....)
Dim boCart As Cart
Dim iUserID As Integer
Dim sqlReader As SqlDataReader
'retrieving the UserID by calling another function
sqlReader = boCart.GetAddress(iUserID)
End Sub
</script>
<form runat="server">
<NETConnect:NETAddress ID="ncBillingAddress" runat="server"/>
</form>
The ASPX page will render the 5 TextBoxes. Now how do I populate the 5
TextBoxes with the records that the stored procedure retrieves for a
particular UserID?OK....this is what I tried in the ASPX page (this ASPX page is named
NETAddress.aspx):
<%@. Register TagPrefix="NETConnect" TagName="Address"
Src="NETAddress.ascx" %>
<%@. Import Namespace="NConnect" %>
<%@. Import Namespace="System.Data" %>
<%@. Import Namespace="System.Data.SqlClient" %>
<script runat="server">
Sub Page_Load(....)
Dim boCart As Cart
Dim iUserID As Integer
Dim sqlReader As SqlDataReader
Dim nAddress As netaddress_ascx
'retrieving the UserID by calling another function
nAddress = Page.LoadControl("NETAddress.ascx")
nAddress.ID = "ncBilling"
pnlAddress.Controls.Add(nAddress)
sqlReader = boCart.GetAddress(iUserID)
Response.Write("Field Count: " & sqlReader.FieldCount)
nAddress.Address = sqlReader.GetString(1)
nAddress.City = sqlReader.GetString(2)
nAddress.StateName = sqlReader.GetString(3)
nAddress.Country = sqlReader.GetString(4)
nAddress.Zip = sqlReader.GetString(5)
End Sub
</script>
<form runat="server">
<asp:Panel ID="pnlAddress" runat="server"/>
</form>
But the above generates this error:
Invalid attempt to read when no data is present.
pointing to
nAddress.Address = sqlReader.GetString(1)
What's causing the error? Note the Response.Write(sqlReader.FieldCount)
line. If I comment out all the GetString lines after this line, then
sqlReader.FieldCount correctly displays the field count as 6. So how
come sqlReader.GetString(1) has no data?
Moreover if I bind the data to a DataList, then also the DataList
renders all the records corresponding to the UserID; so where am I
going wrong?
rn5a@.rediffmail.com wrote:
> This function in a VB class file takes UserID as a parameter & returns
> a SqlDataReader to the calling function which exists in a ASPX page:
> Namespace NConnect
> Public Class Cart
> Private sqlConn As New SqlConnection("....")
> Public Function GetAddress(ByVal UserID As Integer) As
> SqlDataReader
> Dim sqlCmd As SqlCommand
> Dim sqlReader As SqlDataReader
> sqlCmd = New SqlCommand("NETGetAddress", sqlConn)
> sqlCmd.CommandType = CommandType.StoredProcedure
> Try
> With sqlCmd
> .Parameters.Add("@.UserID", SqlDbType.Int).Value =
> UserID
> End With
> sqlConn.Open()
> sqlReader = sqlCmd.ExecuteReader
> Catch ex As Exception
> Throw ex
> End Try
> Return sqlReader
> End Function
> End Class
> End Namespace
> Using vbc, I successfully compiled the above class file into a DLL
> named NConnect.dll.
> This is the simple stored procedure:
> CREATE PROCEDURE NETGetAddress
> @.UserID integer
> AS
> SELECT UserID, Address, City, State, Country, Zip FROM tblUsers WHERE
> UserID = @.UserID
> The ASPX page uses a user control named 'Address.ascx' which has 5
> TextBoxes named txtAddress, txtCity, txtState, txtCountry & txtZip. I
> am using the Get & Set statement for creating a property for each of
> the TextBoxes like this:
> Public Property Address() As String
> Get
> Address = txtAddress.Text
> End Get
> Set(ByVal value As String)
> txtAddress.Text = value
> End Set
> End Property
> 'here comes the other properties
> Finally, this is the ASPX page:
> <%@. Register TagPrefix="NETConnect" TagName="Address"
> src="http://pics.10026.com/?src=NETAddress.ascx" %>
> <%@. Import Namespace="NConnect" %>
> <%@. Import Namespace="System.Data" %>
> <%@. Import Namespace="System.Data.SqlClient" %>
> <script runat="server">
> Sub Page_Load(....)
> Dim boCart As Cart
> Dim iUserID As Integer
> Dim sqlReader As SqlDataReader
> 'retrieving the UserID by calling another function
> sqlReader = boCart.GetAddress(iUserID)
> End Sub
> </script>
> <form runat="server">
> <NETConnect:NETAddress ID="ncBillingAddress" runat="server"/>
> </form>
> The ASPX page will render the 5 TextBoxes. Now how do I populate the 5
> TextBoxes with the records that the stored procedure retrieves for a
> particular UserID?
Well...the mistake I was making was I wasn't looping through the
SqlDataReader using the Read method of the SqlDataReader...
While(sqlReader.Read)
nAddress.Address = sqlReader.GetString(1)
nAddress.City = sqlReader.GetString(2)
nAddress.StateName = sqlReader.GetString(3)
nAddress.Country = sqlReader.GetString(4)
nAddress.Zip = sqlReader.GetString(5)
End While
rn5a@.rediffmail.com wrote:
> OK....this is what I tried in the ASPX page (this ASPX page is named
> NETAddress.aspx):
> <%@. Register TagPrefix="NETConnect" TagName="Address"
> src="http://pics.10026.com/?src=NETAddress.ascx" %>
> <%@. Import Namespace="NConnect" %>
> <%@. Import Namespace="System.Data" %>
> <%@. Import Namespace="System.Data.SqlClient" %>
> <script runat="server">
> Sub Page_Load(....)
> Dim boCart As Cart
> Dim iUserID As Integer
> Dim sqlReader As SqlDataReader
> Dim nAddress As netaddress_ascx
> 'retrieving the UserID by calling another function
> nAddress = Page.LoadControl("NETAddress.ascx")
> nAddress.ID = "ncBilling"
> pnlAddress.Controls.Add(nAddress)
> sqlReader = boCart.GetAddress(iUserID)
> Response.Write("Field Count: " & sqlReader.FieldCount)
> nAddress.Address = sqlReader.GetString(1)
> nAddress.City = sqlReader.GetString(2)
> nAddress.StateName = sqlReader.GetString(3)
> nAddress.Country = sqlReader.GetString(4)
> nAddress.Zip = sqlReader.GetString(5)
> End Sub
> </script>
> <form runat="server">
> <asp:Panel ID="pnlAddress" runat="server"/>
> </form>
> But the above generates this error:
> Invalid attempt to read when no data is present.
> pointing to
> nAddress.Address = sqlReader.GetString(1)
> What's causing the error? Note the Response.Write(sqlReader.FieldCount)
> line. If I comment out all the GetString lines after this line, then
> sqlReader.FieldCount correctly displays the field count as 6. So how
> come sqlReader.GetString(1) has no data?
> Moreover if I bind the data to a DataList, then also the DataList
> renders all the records corresponding to the UserID; so where am I
> going wrong?
>
> rn5a@.rediffmail.com wrote:

Populate TextBox With DB Records

This function in a VB class file takes UserID as a parameter & returns
a SqlDataReader to the calling function which exists in a ASPX page:

Namespace NConnect
Public Class Cart
Private sqlConn As New SqlConnection("....")
Public Function GetAddress(ByVal UserID As Integer) As
SqlDataReader
Dim sqlCmd As SqlCommand
Dim sqlReader As SqlDataReader

sqlCmd = New SqlCommand("NETGetAddress", sqlConn)
sqlCmd.CommandType = CommandType.StoredProcedure

Try
With sqlCmd
.Parameters.Add("@dotnet.itags.org.UserID", SqlDbType.Int).Value =
UserID
End With

sqlConn.Open()
sqlReader = sqlCmd.ExecuteReader
Catch ex As Exception
Throw ex
End Try

Return sqlReader
End Function
End Class
End Namespace

Using vbc, I successfully compiled the above class file into a DLL
named NConnect.dll.

This is the simple stored procedure:

CREATE PROCEDURE NETGetAddress
@dotnet.itags.org.UserID integer
AS
SELECT UserID, Address, City, State, Country, Zip FROM tblUsers WHERE
UserID = @dotnet.itags.org.UserID

The ASPX page uses a user control named 'Address.ascx' which has 5
TextBoxes named txtAddress, txtCity, txtState, txtCountry & txtZip. I
am using the Get & Set statement for creating a property for each of
the TextBoxes like this:

Public Property Address() As String
Get
Address = txtAddress.Text
End Get
Set(ByVal value As String)
txtAddress.Text = value
End Set
End Property

'here comes the other properties

Finally, this is the ASPX page:

<%@dotnet.itags.org. Register TagPrefix="NETConnect" TagName="Address"
Src="NETAddress.ascx" %>
<%@dotnet.itags.org. Import Namespace="NConnect" %>
<%@dotnet.itags.org. Import Namespace="System.Data" %>
<%@dotnet.itags.org. Import Namespace="System.Data.SqlClient" %>

<script runat="server">
Sub Page_Load(....)
Dim boCart As Cart
Dim iUserID As Integer
Dim sqlReader As SqlDataReader

'retrieving the UserID by calling another function
sqlReader = boCart.GetAddress(iUserID)
End Sub
</script>

<form runat="server">
<NETConnect:NETAddress ID="ncBillingAddress" runat="server"/>
</form>

The ASPX page will render the 5 TextBoxes. Now how do I populate the 5
TextBoxes with the records that the stored procedure retrieves for a
particular UserID?OK....this is what I tried in the ASPX page (this ASPX page is named
NETAddress.aspx):

<%@. Register TagPrefix="NETConnect" TagName="Address"
Src="NETAddress.ascx" %>
<%@. Import Namespace="NConnect" %>
<%@. Import Namespace="System.Data" %>
<%@. Import Namespace="System.Data.SqlClient" %>

<script runat="server">
Sub Page_Load(....)
Dim boCart As Cart
Dim iUserID As Integer
Dim sqlReader As SqlDataReader
Dim nAddress As netaddress_ascx

'retrieving the UserID by calling another function

nAddress = Page.LoadControl("NETAddress.ascx")
nAddress.ID = "ncBilling"
pnlAddress.Controls.Add(nAddress)

sqlReader = boCart.GetAddress(iUserID)

Response.Write("Field Count: " & sqlReader.FieldCount)
nAddress.Address = sqlReader.GetString(1)
nAddress.City = sqlReader.GetString(2)
nAddress.StateName = sqlReader.GetString(3)
nAddress.Country = sqlReader.GetString(4)
nAddress.Zip = sqlReader.GetString(5)
End Sub
</script>
<form runat="server">
<asp:Panel ID="pnlAddress" runat="server"/>
</form>

But the above generates this error:

Invalid attempt to read when no data is present.

pointing to

nAddress.Address = sqlReader.GetString(1)

What's causing the error? Note the Response.Write(sqlReader.FieldCount)
line. If I comment out all the GetString lines after this line, then
sqlReader.FieldCount correctly displays the field count as 6. So how
come sqlReader.GetString(1) has no data?

Moreover if I bind the data to a DataList, then also the DataList
renders all the records corresponding to the UserID; so where am I
going wrong?

rn5a@.rediffmail.com wrote:

Quote:

Originally Posted by

This function in a VB class file takes UserID as a parameter & returns
a SqlDataReader to the calling function which exists in a ASPX page:
>
Namespace NConnect
Public Class Cart
Private sqlConn As New SqlConnection("....")
Public Function GetAddress(ByVal UserID As Integer) As
SqlDataReader
Dim sqlCmd As SqlCommand
Dim sqlReader As SqlDataReader
>
sqlCmd = New SqlCommand("NETGetAddress", sqlConn)
sqlCmd.CommandType = CommandType.StoredProcedure
>
Try
With sqlCmd
.Parameters.Add("@.UserID", SqlDbType.Int).Value =
UserID
End With
>
sqlConn.Open()
sqlReader = sqlCmd.ExecuteReader
Catch ex As Exception
Throw ex
End Try
>
Return sqlReader
End Function
End Class
End Namespace
>
Using vbc, I successfully compiled the above class file into a DLL
named NConnect.dll.
>
This is the simple stored procedure:
>
CREATE PROCEDURE NETGetAddress
@.UserID integer
AS
SELECT UserID, Address, City, State, Country, Zip FROM tblUsers WHERE
UserID = @.UserID
>
The ASPX page uses a user control named 'Address.ascx' which has 5
TextBoxes named txtAddress, txtCity, txtState, txtCountry & txtZip. I
am using the Get & Set statement for creating a property for each of
the TextBoxes like this:
>
Public Property Address() As String
Get
Address = txtAddress.Text
End Get
Set(ByVal value As String)
txtAddress.Text = value
End Set
End Property
>
'here comes the other properties
>
Finally, this is the ASPX page:
>
<%@. Register TagPrefix="NETConnect" TagName="Address"
Src="NETAddress.ascx" %>
<%@. Import Namespace="NConnect" %>
<%@. Import Namespace="System.Data" %>
<%@. Import Namespace="System.Data.SqlClient" %>
>
<script runat="server">
Sub Page_Load(....)
Dim boCart As Cart
Dim iUserID As Integer
Dim sqlReader As SqlDataReader
>
'retrieving the UserID by calling another function
sqlReader = boCart.GetAddress(iUserID)
End Sub
</script>
>
<form runat="server">
<NETConnect:NETAddress ID="ncBillingAddress" runat="server"/>
</form>
>
The ASPX page will render the 5 TextBoxes. Now how do I populate the 5
TextBoxes with the records that the stored procedure retrieves for a
particular UserID?


Well...the mistake I was making was I wasn't looping through the
SqlDataReader using the Read method of the SqlDataReader...

While(sqlReader.Read)
nAddress.Address = sqlReader.GetString(1)
nAddress.City = sqlReader.GetString(2)
nAddress.StateName = sqlReader.GetString(3)
nAddress.Country = sqlReader.GetString(4)
nAddress.Zip = sqlReader.GetString(5)
End While

rn5a@.rediffmail.com wrote:

Quote:

Originally Posted by

OK....this is what I tried in the ASPX page (this ASPX page is named
NETAddress.aspx):
>
<%@. Register TagPrefix="NETConnect" TagName="Address"
Src="NETAddress.ascx" %>
<%@. Import Namespace="NConnect" %>
<%@. Import Namespace="System.Data" %>
<%@. Import Namespace="System.Data.SqlClient" %>
>
<script runat="server">
Sub Page_Load(....)
Dim boCart As Cart
Dim iUserID As Integer
Dim sqlReader As SqlDataReader
Dim nAddress As netaddress_ascx
>
'retrieving the UserID by calling another function
>
nAddress = Page.LoadControl("NETAddress.ascx")
nAddress.ID = "ncBilling"
pnlAddress.Controls.Add(nAddress)
>
sqlReader = boCart.GetAddress(iUserID)
>
Response.Write("Field Count: " & sqlReader.FieldCount)
nAddress.Address = sqlReader.GetString(1)
nAddress.City = sqlReader.GetString(2)
nAddress.StateName = sqlReader.GetString(3)
nAddress.Country = sqlReader.GetString(4)
nAddress.Zip = sqlReader.GetString(5)
End Sub
</script>
<form runat="server">
<asp:Panel ID="pnlAddress" runat="server"/>
</form>
>
But the above generates this error:
>
Invalid attempt to read when no data is present.
>
pointing to
>
nAddress.Address = sqlReader.GetString(1)
>
What's causing the error? Note the Response.Write(sqlReader.FieldCount)
line. If I comment out all the GetString lines after this line, then
sqlReader.FieldCount correctly displays the field count as 6. So how
come sqlReader.GetString(1) has no data?
>
Moreover if I bind the data to a DataList, then also the DataList
renders all the records corresponding to the UserID; so where am I
going wrong?
>
>
rn5a@.rediffmail.com wrote:

Quote:

Originally Posted by

This function in a VB class file takes UserID as a parameter & returns
a SqlDataReader to the calling function which exists in a ASPX page:

Namespace NConnect
Public Class Cart
Private sqlConn As New SqlConnection("....")
Public Function GetAddress(ByVal UserID As Integer) As
SqlDataReader
Dim sqlCmd As SqlCommand
Dim sqlReader As SqlDataReader

sqlCmd = New SqlCommand("NETGetAddress", sqlConn)
sqlCmd.CommandType = CommandType.StoredProcedure

Try
With sqlCmd
.Parameters.Add("@.UserID", SqlDbType.Int).Value =
UserID
End With

sqlConn.Open()
sqlReader = sqlCmd.ExecuteReader
Catch ex As Exception
Throw ex
End Try

Return sqlReader
End Function
End Class
End Namespace

Using vbc, I successfully compiled the above class file into a DLL
named NConnect.dll.

This is the simple stored procedure:

CREATE PROCEDURE NETGetAddress
@.UserID integer
AS
SELECT UserID, Address, City, State, Country, Zip FROM tblUsers WHERE
UserID = @.UserID

The ASPX page uses a user control named 'Address.ascx' which has 5
TextBoxes named txtAddress, txtCity, txtState, txtCountry & txtZip. I
am using the Get & Set statement for creating a property for each of
the TextBoxes like this:

Public Property Address() As String
Get
Address = txtAddress.Text
End Get
Set(ByVal value As String)
txtAddress.Text = value
End Set
End Property

'here comes the other properties

Finally, this is the ASPX page:

<%@. Register TagPrefix="NETConnect" TagName="Address"
src="http://pics.10026.com/?src=NETAddress.ascx" %>
<%@. Import Namespace="NConnect" %>
<%@. Import Namespace="System.Data" %>
<%@. Import Namespace="System.Data.SqlClient" %>

<script runat="server">
Sub Page_Load(....)
Dim boCart As Cart
Dim iUserID As Integer
Dim sqlReader As SqlDataReader

'retrieving the UserID by calling another function
sqlReader = boCart.GetAddress(iUserID)
End Sub
</script>

<form runat="server">
<NETConnect:NETAddress ID="ncBillingAddress" runat="server"/>
</form>

The ASPX page will render the 5 TextBoxes. Now how do I populate the 5
TextBoxes with the records that the stored procedure retrieves for a
particular UserID?

Populate textbox with data source.

Hi all, this is my first post. I'm new-ish to .NET and have some basics to cover. I have an older VB/ASP/ActiveX scripting background but I'm tyring to bust into .NET so here's my first question.

I have an existing ASP app I'm trying to mimic as exercise. I have methodology to 'modify a user'. Quite Simple.

Pull 4-5 fields, populate text boxes with what's form the DB, let it be modified and then saved/updated.

background: I've done it with a data grid. Not what I'm after. The menu of the app lets you choose a User from a drop down. On change, querystring the dropdown's value to the 'modifyuser.aspx' page.

ModifyUser.aspx has FirstName, LastName, Password. PermissionLevel, fields.

Permission Level is a drop down, but names/password are textboxes.

I have a SQLDatasource and an ObjectDataSource on the page, (not sure the difference, so I'm trying either)
The datasources are calling GetUser() Stored Procedure which takes one param, UserID (int) from the QueryString.

That is all set... the thing I'm asking is,..

1..how do I set the values of the name/password textboxes to the values from the data sources when the page loads?

2...How do I differentiate when the page is/has updated and inform on successful update, (pause 2 secs) then return to menu?

To view the actual old ASP app, http://www.beaudamore.com/ProductionManagement is the link. I've done this all manually in the old app with Javascript but I'd like to stay as VisualStudio Drag/Drop as possible and let VS do the JS writing for every different browser, etc. Moving to using as little custom JS as possible.

(If there is a better way of laying out the flow/functionality of managing users, etc, I'm open to that as well. This app is a few years old and heavily custom so, it was what the client wanted at the time.)

Thanks a bunch and I'll be posting away like crazy.

SqlDataSource controls encapsulate the ADO.NET code that you would itherwise have to write to open connections, execute command and clean up afterwards, saving you from having to do this yourself. ObjectDataSources are different. They allow you to specify methods that you write in custom classes that perform this functionality and bind these to controls.

As far as your form is concerned, you should use a FormView or DetailsView to display the data, and configure the sqldatasource with hthe names of your procs for update, select etc.

More on how to use them here:http://quickstarts.asp.net/QuickStartv20/aspnet/doc/data/templates.aspx#formview


ok, thanks for the info. Helpful.

One issue:In formview/details view, how to I enforce requirements per column for input?

On a form with textboxes, I use data validators... how do I use a data validator with a details view or form view?

See what I mean? I need to maintain the exact look/feel of the primary 'initian input' phase. 'Modify' phases should look exactly like the input. I do not use a detail view for inputs, I'm using textboxes and data validators... I just want to use the same thing, but populate the textboxes on load using a querystring'd 'UserID' to the 'Modify User' page. Form/Details views, don't do it.

thanks again.


UPDATE:

I did this--

Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim strSQLFirstName As String

strSQLFirstName = "SELECT FirstName FROM Users " _
& "WHERE uniqueid='" & Request.QueryString("UserID") & "'"

myConnection = New OleDbConnection(System.Configuration.ConfigurationManager.AppSettings("strConn"))

myCommand = New OleDbCommand(strSQLFirstName, myConnection)

myConnection.Open()
FirstNameTextbox.Text = myCommand.ExecuteScalar()
myConnection.Close()

BUT..... Do I have to write a seperate SQL string for EACH text box? Forgive me, I'm used to old ASP, I get a recordset from "select * from Users", and can access each field via rs.(FieldName")

I don't want to have to do a .ExecuteScalar() for each textbox.... unless there's no other way?... Is there a way to get a recordset in .NET and access each Field, and plop them into the textbox.text properties?... please say yes.

Otherwise, I have to write a seelct per field and executeScalar to each .text property like I've done above.

? Thanks again


no its much more easy in asp.net you can use the DataReader for this add the following after myConnection.Open(), I am not a VB guy but its easy to covert it to vb.net i think you should remove the braces and semi colons in VB.NET

OleDbDataReader dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

while (dr.Read())

{

FirstNameTextbox.Text =Convert.ToString(dr["FirstName"]);

}


As SharpGuy said, the closest thing to an old ASP recordset is the DataReader, which provides forward only access to a bunch of records. So the equivalent of the following classic ASP:

Do Until rs.EOF
'process various records
'such as placing them in variables
rs.MoveNext
Loop

is:

While MyDataReader.Read()
TextBox1.Text = MyDataReader("FirstName").ToString()
TextBox2.Text = MyDataReader("LastName").ToString()
TextBox3.Text = MyDataReader("Telephone").ToString()
End While

Alternatively, you would set your SqlDataSource up with a SelectCommand, as well as the InsertCommand, using the querystring value as a Parameter. Then your FormView would contain a ItemTemplate to show the record details that were returned by the SelectCommand.

You are using OleDb, so I assume Access? If so, you will probably find this helpful:http://msconline.maconstate.edu/tutorials/ASPNET20/default.htm


Yes, that was it, thanks both of you. Very much. Here's where I am now.

Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim strSQLFirstName As String
Dim myDataReader As OleDbDataReader

strSQLFirstName = "SELECT * FROM Users " _
& "WHERE uniqueid='" & Request.QueryString("UserID") & "'"

myConnection = New OleDbConnection(System.Configuration.ConfigurationManager.AppSettings("strConn"))

myCommand = New OleDbCommand(strSQLFirstName, myConnection)

myConnection.Open()
myDataReader = myCommand.ExecuteReader()
Do While (myDataReader.Read())
TextboxFirstName.Text = Convert.ToString(myDataReader("FirstName"))
TextboxLastName.Text = Convert.ToString(myDataReader("LastName"))
TextboxAddress1.Text = Convert.ToString(myDataReader("Address1"))
TextboxAddress2.Text = Convert.ToString(myDataReader("Address2"))
TextboxCity.Text = Convert.ToString(myDataReader("City"))
DropDownState.SelectedValue = Convert.ToString(myDataReader("State"))
TextBoxZipCode.Text = Convert.ToString(myDataReader("Zip"))
TextBoxPhone.Text = Convert.ToString(myDataReader("Phone"))
TextBoxEmail.Text = Convert.ToString(myDataReader("emailaddress"))
TextboxUsername.Text = Convert.ToString(myDataReader("Username"))
TextboxPassword.Text = Convert.ToString(myDataReader("Password"))
DropDownListPermissionLevel.SelectedValue = myDataReader("PermissionLevel")
CheckBoxDeleted.Checked = Convert.ToBoolean(myDataReader("Deleted"))
Loop
myDataReader.Close()
myConnection.Close()

ok...NOW....lol... how should I handle it, for posting the new data? something about 'ispostback' conditional? (I am ASP/VB fluent, just new to .NET)

How do I catch it that the page's been resubmitted after populated? Already have the StoredProcedure written to take proper params. Because now it's filling in all my text boxes and allowing my DataValidators to work their expression wonders :)

Very happy, moving right along.

(should I make a seperate post now for the submit/posting questions and mark the 'answer' for this post?
I wanna conform to forum standard practice here, ya know?)

--

PS I'm using SQL 2005

--


If there's nothing else on the page that could cause a postback, then yes - check for Page.isPostBack in the load event.

If there are other things on the page that could cause a postback, then you might want to use the onClick method of an <asp:button .../>. If you want to pass arguments aswell, then still using an asp:button, use the commandArgument and onCommand method. Example below:

http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.button.commandargument.aspx


You can create a conditional in your Page_Load event.

If Page.IsPostBack Then
'validate and perform the insert
'set the FromView.Visible = False
'Display a "Success" message
End If

As far as supplementary questions go in the future, that's a grey area. I reckon the one you asked here is acceptable, but any more should go in a new post.


Thanks all.

Populate Textboxes?

I am trying to populate a textbox with a random number and for the life of me I cant get the textbox to populate... any help?

Sub Page_Load()

Dim oRandom As New Random()
Dim iNum As Integer
iNum = oRandom.Next(1, 100000)

textbox1.text = iNum

end sub

I run the page and the textbox is still blank.Is the textbox standalone in the page, or is it nested in a formview?

Can you put anything in the textbox, i.e. textbox.text = "something"
no its not letting me put textbox1.text ="anything" ... I do have it between Form tags...

Im lost
Is it supposed to populate on page load? If so do you have te call inside an if not isportback...
yea I would like for it to populate on the page load
In that case, on the page load sub, add the following:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If Not IsPostBack Then
'Put all your page load stuff in here including the textbox piece
Dim oRandom As New Random()
Dim iNum As Integer
iNum = oRandom.Next(1, 100000)

textbox1.text = iNum

End If

End Sub
bah Im an idiot... lol... thanks...

Anjari

Friday, March 16, 2012

Populating a Textbox

This seems like a simple thing to do, but I cannot figure it out.
How can I populate a textbox with a value retreived from a SQL database so that it is editable?

Thank you!There's no true data binding in ASP; you've got to write code to retrieve the value and more code to update it. The following code will retrieve the value. You'll also need an Update query to update the value.
Good luck
<code>

Dim oConnAsNew Data.SqlClient.SqlConnection(sConnect)

Dim oCmdAsNew Data.SqlClient.SqlCommand

Dim oDSAsNew DataSet

Dim oDAAsNew SqlClient.SqlDataAdapter

Try

With oCmd

.CommandText = "Select Value From Table1"

.Connection = oConn

EndWith

With oDA

.SelectCommand = oCmd

oConn.Open()

.Fill(oDS)

Textbox1.text =ods.Tables(0).Rows(0).Item(0)


EndWith
</code>


What kind of object are you storing your value in? Is it just a single value you are getting back from the database? If so you could use the ExecuteScalar routine to put it into a string and then assign it to a text box. If you have it in a datatable, you just have to assign the proper cell to the text box:

textBox.Text = myDataTable.Rows(rowCounter).Cells("'myField")


As Mr Jkcnack said that if you are retrieving single value use ExecuteScaler method if you are retieving multiple values use dataReader.

Populating a text field and then getting its value

If I change the textbox property Readonly to false then it works perfectly
fine. I am using the latest Beta 2 release of .net framework.
Imran.

"Grant Merwitz" <grant@dotnet.itags.org.workshare.com> wrote in message
news:O0YmSUcmFHA.576@dotnet.itags.org.TK2MSFTNGP15.phx.gbl...
> Thats a strange one.
> Working fine for me:
> ASPX:
> <asp:TextBox id="TextBox1" runat="server" ReadOnly="True"
> OnClick="Button1_Click"></asp:TextBox>
> <asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
> CS
> void Page_Load(object sender, System.EventArgs e)
> {
> if(!Page.IsPostBack)
> TextBox1.Text = "Hello";
> }
> void Button1_Click(object sender, System.EventArgs e)
> {
> Response.Write("Value: " + TextBox1.Text);
> }
> OUTPUT
> Value: Hello
>
> Try making a simple page like that and testing it
>
> "Imran Aziz" <imran@dotnet.itags.org.tb2.net> wrote in message
> news:e43rNIcmFHA.2860@dotnet.itags.org.TK2MSFTNGP15.phx.gbl...
>> Hello All,
>> I am populating a text field dynamic in my code, and its a read-only
>> textbox control. It populates it perfectly fine. but when I get its value
>> back in code I get an empty string any clues as to how to get this sorted
>> please ?
>>
>> Here is how I set the value of the control.
>> txtTitle.Text = feed.Channels[0].Title;
>>
>> and get it later
>>
>> String strString = txtTitle.Text;
>>
>> Any clues please ?
>>
>> Imran.
>>okay, i'm on v1.1

I have beta 2 on a machine here.
If i have time to test it before i go, i'll try run the example there

"Imran Aziz" <imran@.tb2.net> wrote in message
news:%23rwRZUdmFHA.2860@.TK2MSFTNGP15.phx.gbl...
> If I change the textbox property Readonly to false then it works
> perfectly fine. I am using the latest Beta 2 release of .net framework.
> Imran.
> "Grant Merwitz" <grant@.workshare.com> wrote in message
> news:O0YmSUcmFHA.576@.TK2MSFTNGP15.phx.gbl...
>> Thats a strange one.
>> Working fine for me:
>>
>> ASPX:
>>
>> <asp:TextBox id="TextBox1" runat="server" ReadOnly="True"
>> OnClick="Button1_Click"></asp:TextBox>
>> <asp:Button id="Button1" runat="server"
>> Text="Button"></asp:Button>
>>
>> CS
>>
>> void Page_Load(object sender, System.EventArgs e)
>> {
>> if(!Page.IsPostBack)
>> TextBox1.Text = "Hello";
>> }
>>
>> void Button1_Click(object sender, System.EventArgs e)
>> {
>> Response.Write("Value: " + TextBox1.Text);
>> }
>>
>> OUTPUT
>>
>> Value: Hello
>>
>>
>> Try making a simple page like that and testing it
>>
>>
>> "Imran Aziz" <imran@.tb2.net> wrote in message
>> news:e43rNIcmFHA.2860@.TK2MSFTNGP15.phx.gbl...
>>> Hello All,
>>> I am populating a text field dynamic in my code, and its a read-only
>>> textbox control. It populates it perfectly fine. but when I get its
>>> value back in code I get an empty string any clues as to how to get this
>>> sorted please ?
>>>
>>> Here is how I set the value of the control.
>>> txtTitle.Text = feed.Channels[0].Title;
>>>
>>> and get it later
>>>
>>> String strString = txtTitle.Text;
>>>
>>> Any clues please ?
>>>
>>> Imran.
>>>
>>
>>
Thanks a lot.
Imran.
"Grant Merwitz" <grant@.workshare.com> wrote in message
news:u9$zKbdmFHA.3936@.TK2MSFTNGP10.phx.gbl...
> okay, i'm on v1.1
> I have beta 2 on a machine here.
> If i have time to test it before i go, i'll try run the example there
> "Imran Aziz" <imran@.tb2.net> wrote in message
> news:%23rwRZUdmFHA.2860@.TK2MSFTNGP15.phx.gbl...
>> If I change the textbox property Readonly to false then it works
>> perfectly fine. I am using the latest Beta 2 release of .net framework.
>> Imran.
>>
>> "Grant Merwitz" <grant@.workshare.com> wrote in message
>> news:O0YmSUcmFHA.576@.TK2MSFTNGP15.phx.gbl...
>>> Thats a strange one.
>>> Working fine for me:
>>>
>>> ASPX:
>>>
>>> <asp:TextBox id="TextBox1" runat="server" ReadOnly="True"
>>> OnClick="Button1_Click"></asp:TextBox>
>>> <asp:Button id="Button1" runat="server"
>>> Text="Button"></asp:Button>
>>>
>>> CS
>>>
>>> void Page_Load(object sender, System.EventArgs e)
>>> {
>>> if(!Page.IsPostBack)
>>> TextBox1.Text = "Hello";
>>> }
>>>
>>> void Button1_Click(object sender, System.EventArgs e)
>>> {
>>> Response.Write("Value: " + TextBox1.Text);
>>> }
>>>
>>> OUTPUT
>>>
>>> Value: Hello
>>>
>>>
>>> Try making a simple page like that and testing it
>>>
>>>
>>> "Imran Aziz" <imran@.tb2.net> wrote in message
>>> news:e43rNIcmFHA.2860@.TK2MSFTNGP15.phx.gbl...
>>>> Hello All,
>>>> I am populating a text field dynamic in my code, and its a read-only
>>>> textbox control. It populates it perfectly fine. but when I get its
>>>> value back in code I get an empty string any clues as to how to get
>>>> this sorted please ?
>>>>
>>>> Here is how I set the value of the control.
>>>> txtTitle.Text = feed.Channels[0].Title;
>>>>
>>>> and get it later
>>>>
>>>> String strString = txtTitle.Text;
>>>>
>>>> Any clues please ?
>>>>
>>>> Imran.
>>>>
>>>
>>>
>>
>>
Sorry it took me so long to try this.

But it's working fine for me on a Machine running Beta 2

"Imran Aziz" <imran@.tb2.net> wrote in message
news:ujgDxxdmFHA.2472@.TK2MSFTNGP15.phx.gbl...
> Thanks a lot.
> Imran.
> "Grant Merwitz" <grant@.workshare.com> wrote in message
> news:u9$zKbdmFHA.3936@.TK2MSFTNGP10.phx.gbl...
>> okay, i'm on v1.1
>>
>> I have beta 2 on a machine here.
>> If i have time to test it before i go, i'll try run the example there
>>
>> "Imran Aziz" <imran@.tb2.net> wrote in message
>> news:%23rwRZUdmFHA.2860@.TK2MSFTNGP15.phx.gbl...
>>> If I change the textbox property Readonly to false then it works
>>> perfectly fine. I am using the latest Beta 2 release of .net framework.
>>> Imran.
>>>
>>> "Grant Merwitz" <grant@.workshare.com> wrote in message
>>> news:O0YmSUcmFHA.576@.TK2MSFTNGP15.phx.gbl...
>>>> Thats a strange one.
>>>> Working fine for me:
>>>>
>>>> ASPX:
>>>>
>>>> <asp:TextBox id="TextBox1" runat="server" ReadOnly="True"
>>>> OnClick="Button1_Click"></asp:TextBox>
>>>> <asp:Button id="Button1" runat="server"
>>>> Text="Button"></asp:Button>
>>>>
>>>> CS
>>>>
>>>> void Page_Load(object sender, System.EventArgs e)
>>>> {
>>>> if(!Page.IsPostBack)
>>>> TextBox1.Text = "Hello";
>>>> }
>>>>
>>>> void Button1_Click(object sender, System.EventArgs e)
>>>> {
>>>> Response.Write("Value: " + TextBox1.Text);
>>>> }
>>>>
>>>> OUTPUT
>>>>
>>>> Value: Hello
>>>>
>>>>
>>>> Try making a simple page like that and testing it
>>>>
>>>>
>>>> "Imran Aziz" <imran@.tb2.net> wrote in message
>>>> news:e43rNIcmFHA.2860@.TK2MSFTNGP15.phx.gbl...
>>>>> Hello All,
>>>>> I am populating a text field dynamic in my code, and its a
>>>>> read-only textbox control. It populates it perfectly fine. but when I
>>>>> get its value back in code I get an empty string any clues as to how
>>>>> to get this sorted please ?
>>>>>
>>>>> Here is how I set the value of the control.
>>>>> txtTitle.Text = feed.Channels[0].Title;
>>>>>
>>>>> and get it later
>>>>>
>>>>> String strString = txtTitle.Text;
>>>>>
>>>>> Any clues please ?
>>>>>
>>>>> Imran.
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
Hum strange I am doing something wrong then, I guess I will try and use
labels instead of text boxes.
Thanks a lot for coming back to me on that.

Imran
"Grant Merwitz" <grant@.workshare.com> wrote in message
news:eUjjZmNnFHA.3572@.TK2MSFTNGP09.phx.gbl...
> Sorry it took me so long to try this.
> But it's working fine for me on a Machine running Beta 2
>
> "Imran Aziz" <imran@.tb2.net> wrote in message
> news:ujgDxxdmFHA.2472@.TK2MSFTNGP15.phx.gbl...
>> Thanks a lot.
>> Imran.
>> "Grant Merwitz" <grant@.workshare.com> wrote in message
>> news:u9$zKbdmFHA.3936@.TK2MSFTNGP10.phx.gbl...
>>> okay, i'm on v1.1
>>>
>>> I have beta 2 on a machine here.
>>> If i have time to test it before i go, i'll try run the example there
>>>
>>> "Imran Aziz" <imran@.tb2.net> wrote in message
>>> news:%23rwRZUdmFHA.2860@.TK2MSFTNGP15.phx.gbl...
>>>> If I change the textbox property Readonly to false then it works
>>>> perfectly fine. I am using the latest Beta 2 release of .net framework.
>>>> Imran.
>>>>
>>>> "Grant Merwitz" <grant@.workshare.com> wrote in message
>>>> news:O0YmSUcmFHA.576@.TK2MSFTNGP15.phx.gbl...
>>>>> Thats a strange one.
>>>>> Working fine for me:
>>>>>
>>>>> ASPX:
>>>>>
>>>>> <asp:TextBox id="TextBox1" runat="server" ReadOnly="True"
>>>>> OnClick="Button1_Click"></asp:TextBox>
>>>>> <asp:Button id="Button1" runat="server"
>>>>> Text="Button"></asp:Button>
>>>>>
>>>>> CS
>>>>>
>>>>> void Page_Load(object sender, System.EventArgs e)
>>>>> {
>>>>> if(!Page.IsPostBack)
>>>>> TextBox1.Text = "Hello";
>>>>> }
>>>>>
>>>>> void Button1_Click(object sender, System.EventArgs e)
>>>>> {
>>>>> Response.Write("Value: " + TextBox1.Text);
>>>>> }
>>>>>
>>>>> OUTPUT
>>>>>
>>>>> Value: Hello
>>>>>
>>>>>
>>>>> Try making a simple page like that and testing it
>>>>>
>>>>>
>>>>> "Imran Aziz" <imran@.tb2.net> wrote in message
>>>>> news:e43rNIcmFHA.2860@.TK2MSFTNGP15.phx.gbl...
>>>>>> Hello All,
>>>>>> I am populating a text field dynamic in my code, and its a
>>>>>> read-only textbox control. It populates it perfectly fine. but when I
>>>>>> get its value back in code I get an empty string any clues as to how
>>>>>> to get this sorted please ?
>>>>>>
>>>>>> Here is how I set the value of the control.
>>>>>> txtTitle.Text = feed.Channels[0].Title;
>>>>>>
>>>>>> and get it later
>>>>>>
>>>>>> String strString = txtTitle.Text;
>>>>>>
>>>>>> Any clues please ?
>>>>>>
>>>>>> Imran.
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>

Populating a textbox with a datasource

I have a textbox that needs to get it's value from database based on a value parsed from text in another textbox.

I am using a datasource with a select command to hit the database, but I have no need to collect anything but a single value, so it seems very wasteful to have to load anything into a dataset or the like, just to get that one thing to a textbox.

What's the easiest way to get this one value for the textbox?

thanks

Did you thought keep the data in a Session variable?

Your select command should similar to below

SELECT ID FROM table WHERE ID='1'

Now you could use one SqlCommand.ExecuteScalar which only returns 1 value from the database.

Check below link for more information

http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar.aspx

HC


rsegecin:

Did you thought keep the data in a Session variable?

That wouldn't do much because I wouldstill have to do all the fetching to get itinto the session variable, or any other variable for that matter.


Haissam:

Your select command should similar to below

SELECT ID FROM table WHERE ID='1'

Now you could use one SqlCommand.ExecuteScalar which only returns 1 value from the database.

Check below link for more information

http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar.aspx

HC

Yes that is very similar to the SQL I'm using

I was considering ExecuteScalar thought, the drawback is really that it's still a lot of code for one little value, and I have been reusing the datasources pretty religiously so far, eliminating the need for much code at all.

I'm hoping to keep that up, but maybe there is no particularly simple way... I wish datasources had a Scalar command that returned the value :/