Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I bind to a label from a SqlDataSource

Posted on 2011-03-07
7
Medium Priority
?
334 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: 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Integration Management Part 2
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

926 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