Solved

How do I bind to a label from a SqlDataSource

Posted on 2011-03-07
7
319 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
Comment Utility
0
 
LVL 22

Expert Comment

by:plusone3055
Comment Utility
0
 
LVL 9

Author Comment

by:TonyReba
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 9

Expert Comment

by:gery128
Comment Utility
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
Comment Utility
I am trying not to use DataView, or Gridview , only the Label control
0
 
LVL 9

Accepted Solution

by:
gery128 earned 500 total points
Comment Utility
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
Comment Utility
Is comming across now, thank you
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now