473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Databind a Label (or Literal), proper way?

I'll try to keep this short & sweet and hopefully get the direction I'm
looking for.

I'll drop a SqlDatasource onto a webform. Configure it to use a stored
proc, perhaps have the parameters be QueryString parms or Session variables,
whatever the situation calls for.

The Stored Proc will return one row of data, let's say FirstName & LastName,
John Smith.

I drop a Label (or Literal) onto the webform.

I would like the Label's Text property to be set to FirstName.

What/where is the proper way to hook this up?

In the past, I've had a Page_Load event and if not Postback, I setup a
datareader and read the values from the datareader and populate the
label/literal/textbox controls.

But I was thinking there must be a way to utilize the SqlDatasource object
and do the same thing (thus saving having to write all that SP calling code
in the Page_Load).

Thanks,
Brian
Mar 14 '08 #1
1 1662
Hi Brian,

I think you can try the following code to bind your Label control to a
SqlDataSource.

Dim dv As DataView =
CType(SqlDataSource1.Select(DataSourceSelectArgume nts.Empty), DataView)
Dim dr As DataRowView = dv.Item(1)
Me.Label1.Text = dr.Item(0)

Regards,
Manish
www.ComponentOne.com
"Brian Simmons" wrote:
I'll try to keep this short & sweet and hopefully get the direction I'm
looking for.

I'll drop a SqlDatasource onto a webform. Configure it to use a stored
proc, perhaps have the parameters be QueryString parms or Session variables,
whatever the situation calls for.

The Stored Proc will return one row of data, let's say FirstName & LastName,
John Smith.

I drop a Label (or Literal) onto the webform.

I would like the Label's Text property to be set to FirstName.

What/where is the proper way to hook this up?

In the past, I've had a Page_Load event and if not Postback, I setup a
datareader and read the values from the datareader and populate the
label/literal/textbox controls.

But I was thinking there must be a way to utilize the SqlDatasource object
and do the same thing (thus saving having to write all that SP calling code
in the Page_Load).

Thanks,
Brian
Mar 14 '08 #2

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

Similar topics

3
by: Marty McDonald | last post by:
I have <asp:Table... </asp:Table> on my webform. In codebehind, I populate a DataTable whose data should appear in the asp:Table. I created my own code to populate the asp:Table with the...
3
by: Luis Esteban Valencia | last post by:
Hi, the following code displays a search result in a datagrid and is working without problems. But I think the way I have done is not correct especially databind(). could anyone help me to...
1
by: NancyASAP | last post by:
I have a label on my ASP.NET form. It has a cssclass that includes a background color. I am dynamically putting text in this label. The text contains some embedded html (I want to display part...
6
by: Joe | last post by:
I know that the Literal control will not render a <span> tag so I can not format its text. Other than this, what is the difference betwen the Literal control and the LiteralControl Control? How...
2
by: Mark A. Sam | last post by:
Hello, I want to use a literal control to provide information about people listed on a webpage, where the control is on the same line as the person it addresses, so that I have a button, the...
5
by: paul.hester | last post by:
Hi all, I have a custom control with an overridden Render method. Inside this method I'm rendering each control in its collection using their RenderControl method. However, I'm running into a...
2
by: craigkenisston | last post by:
In Asp.Net 2.0 I need to create a very special layout with data coming from an ObjectDataSource. It was already working using a GridView, but I need a free layout. So, I dropped the GridView and...
2
by: rn5a | last post by:
Consider the following code: <script runat="server"> Sub ShowData(obj As Object, ea As EventArgs) lblDate.Text = DateTime.Now.ToString("d") lblDate.DataBind() End Sub </script> <form...
1
by: rn5a | last post by:
This is how I am populating a Panel with dynamic LinkButtons (the no. of LinkButtons that will be created will depend upon the no. of orders a user has placed): Sub Page_Init(obj As Object, ea...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.