Solved

How do I bind to a label from a SqlDataSource

Posted on 2011-03-07
7
324 Views
Last Modified: 2012-05-11
I want to pull the Womens Census Value

   protected void Page_Load(object sender, EventArgs e)
    {
        DataView dvSql = (DataView)SqlDataSource4.Select(DataSourceSelectArguments.Empty);
        foreach (DataRowView drvSql in dvSql)
        {
            lbl_Womens_Census.Text = drvSql["Womens_Census"].ToString();
        }
Data Source
<asp:SqlDataSource ID="SqlDataSource4" runat="server" 
        ConnectionString="<%$ ConnectionStrings:appdevConnectionString1 %>" 
        ProviderName="<%$ ConnectionStrings:appdevConnectionString1.ProviderName %>" 
        
                    SelectCommand="SELECT [ID], [Date], [NT1_Census], [NT1], [NT1_Status], [NT2_Census], [NT2], [NT2_Status], [NT3_Census], [NT3], [NT3_Status], [ICU_Census], [ICU], [ICU_Status], [SDU_Census], [SDU], [SDU_Status], [Tele3rd1_Census], [Tele3rd1], [Tele3rd1_Status], [Tele3rd2_Census], [Tele3rd2], [Tele3rd2_Status], [Tele4th1_Census], [Tele4th1], [Tele4th1_Status], [Tele4th2_Census], [Tele4th2], [Tele4th2_Status], [Pedi3rd_Census], [Pedi3rd], [Pedi3rd_Status], [Pedi4th_Census], [Pedi4th], [Pedi4th_Status], [PICU_SD_Census], [PICU_SD], [PICU_SD_Status], [ER_Census], [ER], [ER_Status], [MICU_Census], [MICU], [MICU_Status], [CPV_Census], [CPV], [CPV_Status], [CVOR_Census], [CVOR], [CVOR_Status], [CLOF_Census], [CLOF], [CLOF_Status], [CVOR_HOLDING_Census], [CVOR_HOLDING], [CVOR_HOLDING_Status], [Behavioral_Census], [Womens_Census], [Rehab_Census] FROM [tb_Bed_Control_Possible]">
    </asp:SqlDataSource>

Open in new window

0
Comment
Question by:TonyReba
  • 3
  • 2
  • 2
7 Comments
 
LVL 22

Expert Comment

by:plusone3055
ID: 35063307
0
 
LVL 22

Expert Comment

by:plusone3055
ID: 35063308
0
 
LVL 9

Author Comment

by:TonyReba
ID: 35063321
I am trying to do the simplest and best way to set the text to the label, can you tell me how/??

possibly modify my snippet above
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 9

Expert Comment

by:gery128
ID: 35065936
Check if you are getting data in DataView properly?
If yes, then you should get value in your label.
0
 
LVL 9

Author Comment

by:TonyReba
ID: 35069548
I am trying not to use DataView, or Gridview , only the Label control
0
 
LVL 9

Accepted Solution

by:
gery128 earned 500 total points
ID: 35070056
TonyReba:

you have used this line in your code:
DataView dvSql = (DataView)SqlDataSource4.Select(DataSourceSelectArguments.Empty);

My question was whether you are getting data in DataView  or not? If you are getting than you should be able to iterate through DataViewRows and get the values. Another way is convert your DataView to table by using dvSql.ToTable(); and than iterate through DataTable.

But by your code, the value should come. please check if DataView is populated with data or not.
0
 
LVL 9

Author Closing Comment

by:TonyReba
ID: 35070242
Is comming across now, thank you
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question