?
Solved

How do I set set the label.text in a gridview FooterRow?

Posted on 2008-10-02
2
Medium Priority
?
233 Views
Last Modified: 2008-10-02
I can't seem to set the text property of a label in a gridview FooterRow.  Stepping through with the debugger reveals I have found the correct control and I don't get any errors, but the label does not appear.  I assume it has something to do with viewstate and postback or something similiar.

The Try/Catch block is where I am attempting to set the label text.
Protected Sub InsertNewEmail(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim newdictionary As ListDictionary = New ListDictionary()
        Dim EmailAddress As String = CType(grdEmails.FooterRow.FindControl("txtNewEmailAddress1"), TextBox).Text
        Dim EmailType As String = CType(grdEmails.FooterRow.FindControl("ddlEmailTypes1"), DropDownList).SelectedValue
        Dim NewEmailAddress As String = EmailAddress
        Dim NewEmailTypeID As String = EmailType
        Dim NewPersonID As String = PersonID
        Dim NewUserID As Guid = UserID
        newdictionary.Add("EmailAddress", NewEmailAddress)
        newdictionary.Add("EmailTypeID", NewEmailTypeID)
        newdictionary.Add("PersonID", NewPersonID)
        newdictionary.Add("UserID", NewUserID)
        Try
            ldsPersonEmails.Insert(newdictionary)
        Catch ex As Data.SqlClient.SqlException
            Dim ExceptionLabel As Label = CType(grdEmails.FooterRow.FindControl("lblException"), Label)
            ExceptionLabel.Text = "Bad User!  Bad!"
        End Try
        grdEmails.DataBind()
    End Sub

Open in new window

0
Comment
Question by:abenage
2 Comments
 
LVL 18

Accepted Solution

by:
David Robitaille earned 2000 total points
ID: 22627075
you problem is your  grdEmails.DataBind() that redraw the grdEmails
set your label outside the drid or try this

 

 Try
            ldsPersonEmails.Insert(newdictionary)
            grdEmails.DataBind()
 
        Catch ex As Data.SqlClient.SqlException
            Dim ExceptionLabel As Label = CType(grdEmails.FooterRow.FindControl("lblException"), Label)
            ExceptionLabel.Text = "Bad User!  Bad!"
        End Try
        

Open in new window

0
 
LVL 1

Author Comment

by:abenage
ID: 22627176
Thanks!!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

830 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