473,545 Members | 2,627 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setting label = datasource...

Roy
Could someone please post some sample code on how to set an <asp:label>
equal to the results of a sql query?

This seems like it should be simple, but I can't seem to get it done.

Nov 19 '05 #1
3 4169
Well what do you get as a return? a SqlDataReader, DataView?
to get every row into the table you'll have to loop around, otherwise, use a
DataGrid to display row by row:

while(pData.Rea d())
Label.Text += pData.GetString (0);

Hope you getting string!

Al

"Roy" wrote:
Could someone please post some sample code on how to set an <asp:label>
equal to the results of a sql query?

This seems like it should be simple, but I can't seem to get it done.

Nov 19 '05 #2
y,

If you are going to have only one value in your result of a sqlquery thenyou
can use the following code to bind that single value to a label box.

Store that single value in a variable,say "MyVariable " for example, and
assign it to label cotrol as follows.

<asp:Label id="Label1" Text ='<%# MyVariable %>' runat=server/>

You've to write the following line in one of your event's let us Page_Load
event

Page.DataBind() ;
cheers,

Jerome. M
"Roy" wrote:
Could someone please post some sample code on how to set an <asp:label>
equal to the results of a sql query?

This seems like it should be simple, but I can't seem to get it done.

Nov 19 '05 #3
Roy
Thanks for the input guys.

Basically, I'm trying to set a label equal to a specific row in a
table. The row would have about 6 columns in it, but it would always be
just a single row. By the same token, I'd like it to look good... Can I
set it equal to a specific field? IOW, break up the row into it's
constituent parts?

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
371
by: TF | last post by:
hi, i am using a ListBox control on a windows form using VB.Net. when i set the DataSource property of the control to an ArrayList it fires following events in this order: SelectedIndexChanged SelectedIndexChanged DataSourceChanged SelectedIndexChanged is there any way to check in SelectedIndexChanged event handler that
0
1749
by: Shravan | last post by:
Hi, I have a Windows Forms Custom DataGrid, which is put in a usercontrol, which on setting DataSource is setting focus to grid. The call stack for setting the focus is as follows. This is not happened always whenever DataSource is set, only called sometimes, in a series of setting DataSource, I could get this setting focus only one time ....
7
20754
by: charliewest | last post by:
Using .Net CF, i have created a 2 dimension ArrayList, and "binded" this list to a ComboBox control using the "DataSource" property. I have set the DisplaySource and ValueMember properties as well. The control populates well, both the display values, and selected values. However, when i try to "set" the SelectedValue or SelectedIndex...
3
2624
by: Harry | last post by:
Hi, Can anyone tell me why the below code does not work. I dont get any errors, but nor does the Text for the asp:label get set. Thanks in advance as always H
2
1786
by: hellrazor | last post by:
Hi there, I'm successfully streaming a list of items into a radiobuttonlist. I am using an ArrayList as a data source, which I have built from a table of values in a MySQL table. It's working great. My only issue is that it is printing the label along the rendering of the radio objects. How do I keep the radiobuttonlist object from...
2
1602
by: H5N1 | last post by:
Hi there First of all excuse me posting such simple (I guess) question, but I didn't find the answer in tutorials. I have a formView presenting records from some table. one of the fields is a Category ID, which is a foreign key. in edit template I replace it with dropdownlist, which is gets this ID, and displays corresponding name, by...
7
2524
by: rn5a | last post by:
How can I place a Label control in the FooterTemplate of a DataList control? I tried this <script runat="server"> Sub Page_Load(obj As Object, ea As EventArgs) Dim dblTotal As Double Dim sqlReader As SqlDataReader
0
1223
by: Rocky | last post by:
Dear ALL, I am facing a bit problem in DATAGRID. so may be you guys can help me out. Actually on a DataGrid I am having following controls: 1) 2 DropDown Menu 2) 1 Text Box 3) 1 ADD Button 4) 1 Remove Button So these all controls are in 1 row and looks like:
1
1740
by: progressdll | last post by:
I'm trying to change the behaviour of setting the DataSource property of combobox. Here is the behaviour I now see. Setting the DataSource property of combobox to an ArrayList will visual display the first value in the Text field of the combobox. ( or setting the Text property ).
0
7428
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7685
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7941
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7452
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6014
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3485
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1916
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
738
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.