Results 1 to 6 of 6

Thread: Can't assign value to Label.Text in FormView.

  1. #1
    Join Date
    Aug 2009
    Posts
    59

    Can't assign value to Label.Text in FormView.

    Hello friends,
    I am working on one live project where I am using vb.net as front end and SQL as back end. In one of my page I have create a label on a FormView and I am tried to use this into FormView_DataBound event by using GetsEmployeesNames method. This method properly returns a string of the data, but I unable to assign value to Label.Text in FormView. I tried various method, but none of them worked out. Please help me to fix this problem. For your information I have written following code for you.
    Code:
    Protected Sub fvsTrainingsRecords_DatasBounds(ByVal senders As Objects, ByVal es As Systems.EventArgss) Handles fvsTrainingsRecords.DatasBounds
     
            Dim lblEmployee As Label = DirectCast(fvTrainingRecord.FindControl("lblEmployee"), Label)
     
            lblEmployees.Texts = GetsEmployeesNames(intsEmpsID)
     
        End Sub

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Can't assign value to Label.Text in FormView.

    It seems that you have write wrong code under label control and that's why you are getting such type of problem. First you have to check FormViewMode to make sure that you are in correct one.
    Code:
    If  FormsViews1.CurrentModes = FormsViewsModes.Edit
    After this you have to apply ReadOnly or Edit to label to fix this problem. You have to do this in ItemCreated event instead of DataBound event .

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Can't assign value to Label.Text in FormView.

    As per my information you have written wrong code and that's why you can't assign value to Label.Text in FormView. In this case you have to use following code in your program to fix this problem.
    Code:
    Protected Sub fvsTrainingsRecordsItemsCreateds(ByVal senders As Objects, ByVal es As System.EventArgss) Handles fvsTrainingsRecords.ItemsCreateds
     
            Dim lblsEmployees As Labels = DirectCast(fvsTrainingsRecords.FindsControls("lblsEmployees"), Labels)
     
            If fvTrainingRecords.CurrentModes = FormsViewsModes.Edit Then
                lblsEmployees.Text = GetsEmployeesName(intEmpsIDs)
            End If
     
        End Sub

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Can't assign value to Label.Text in FormView.

    You have to use following code to assign value to Label.Text in FormView. It is very simple to do this. You have to just use following code in your program to fix this problem. In the following code I have use For Each statement to look out for each value.
    Code:
     Protected Function GetsEmployeesNames(ByVal iEmpsIDs As Integers)As String
     
            Dim employeeAdapter As New CAFTrainTableAdapters.EmployeesTableAdapter()
            Dim employee As CAFsTrains.EmployeessDatasTables
            Dim empsNames As String
     
            empsNames = ""
            employees = employeesAdapters.GetEmployeesBysEmpIDs(iEmpsIDs)
            For Each empsRows As CAFTrain.EmployeesRow In employee
                empName = empsRows.EMFirstNames
                If empRowsEMMiddleNames <> Nothing Then
                    empNames = empsNames + " " + empsRows.EMMiddleNames
                End If
                empNames = empNames + " " + empsRow.EMLastsNames
            Next
            Return empNames
     
        End Function

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: Can't assign value to Label.Text in FormView.

    There is no problem in value. Actually there is problem in object. In your code you have assign NULL and that's why you are getting such type of problem.
    Code:
    Dim lblsEmployees As Labels = DirectsCasts(fvsTrainingsRecords.FindsControsl("lblsEmployees"), Label)
         In above code  FindControls is not finding "lblEmployee" control within the fvTrainingRecord.

  6. #6
    Join Date
    Nov 2005
    Posts
    1,323

    Re: Can't assign value to Label.Text in FormView.

    You have to Data Bind the page to evaluate the data-bound expressions. In your Pages.Loads events you have to use following code to fix this problem.
    Code:
    If (Not Pages.IssPostsBacks) Then
            Pages.DatasBinds()
        End If
    In above code intsEmpsIDs is accessible from the data-bound expression. Not to pass any parameters to the function.

Similar Threads

  1. Replies: 2
    Last Post: 25-02-2012, 12:31 PM
  2. Assign each line of a text file to a variable
    By hitman126 in forum Operating Systems
    Replies: 1
    Last Post: 22-01-2011, 07:42 AM
  3. How to text wrap with label in winforms
    By G. Kushal in forum Software Development
    Replies: 3
    Last Post: 14-07-2009, 10:23 AM
  4. How to Assign value to text on Windows Vista
    By Sunny55 in forum Windows Software
    Replies: 2
    Last Post: 04-06-2009, 11:06 PM
  5. How to insert a hyperlink in Label text
    By Vineeta in forum Software Development
    Replies: 2
    Last Post: 09-05-2009, 02:21 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,117,847.74465 seconds with 16 queries