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

x
?
Solved

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

Posted on 2011-02-11
5
Medium Priority
?
851 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 2000 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

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…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses

877 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