Solved

How to call asp.net GridView's column into vb.net code?

Posted on 2011-02-11
5
838 Views
Last Modified: 2013-11-26
Hello experts,

I have an asp.net database, with email field. And, now I want to get that field, gridview's email column, into vb.net code. I have a code for sending mail, and want to replace Send To(test@yahoo.com) with that field.

Dim Email As New MailMessage("test@gmail.com", "test@yahoo.com", "TEST", body)

Open in new window


Thank you in advance for help to anyone.
0
Comment
Question by:dejandejanovic
  • 3
  • 2
5 Comments
 
LVL 3

Expert Comment

by:jmro20
ID: 34874947
If there are multiple records then something like this:
 
For Each row As GridViewRow In GridView1.Rows
            Dim Email As New MailMessage("test@yahoo.com", row.Cells("YourEmailColumnName").ToString, "TEST", body)
Next

Open in new window

0
 
LVL 3

Accepted Solution

by:
jmro20 earned 500 total points
ID: 34874968
If there is only one record in grid then:
Dim Email As New MailMessage("test@yahoo.com", GridView1.Rows(0).Cells("YourEmailColumnName").ToString, "TEST", body)

Open in new window

0
 

Author Comment

by:dejandejanovic
ID: 34877709
Thank you for reply. I have add your solution, but now get this code error:

Value of type 'System.Web.UI.WebControls.TableCellCollection' cannot be converted to 'String'.

For info my code is beggins with:
Imports System.Net.Mail
Partial Class details
    Inherits System.Web.UI.Page

Any idea?
0
 

Author Comment

by:dejandejanovic
ID: 34878239
Oh, ignore abow message. I didnt ad ToString.

But, still my email form does not send message os I would like to give a picture how my database is design, and work.
1. - From Search.aspx page I have gridview which is filtering by a few Dropdownlists.
    - When select a record from gridview it jump to another page Details.aspx.
2. - Details.aspx contain more informations about this select record.
    - in the end of page I have mail form. First field of this form is EmailGridview2 for which I have send this help (see printscreen).
3. This is my Send mail code:
Protected Sub sendmail(ByVal from As String, ByRef body As String)
        Dim Email As New MailMessage("test@gmail.com", EmailGridView2.Rows(0).Cells("email").ToString, "Subject Testi", body)

        Dim smtpclient As New SmtpClient
        smtpclient.Host = "smtp.gmail.com"
        smtpclient.EnableSsl = True

        Dim credentials As New System.Net.NetworkCredential("SmtpUserID", "SmtpPassword")
        smtpclient.Credentials = credentials
        smtpclient.Send(Email)

        lblValidation.Text = "Success"
        lblValidation.ForeColor = Drawing.Color.DarkGreen
        txtCaptcha.Text = ""
        TextBox1.Focus()
    End Sub

Open in new window


4. I'm still learning asp.net vb.net programming, and maybe do not understand some things. And I hope that I have used right solution, as Detail.aspx display only 1 record. So, I have used your second solution.
printscreen.png
0
 

Author Closing Comment

by:dejandejanovic
ID: 34879738
Found solution. I was just need to add .text.

GridView1.Rows(0).Cells("YourEmailColumnName").text.ToString

Thanks Jmro20.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

760 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

20 Experts available now in Live!

Get 1:1 Help Now