Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-02-11
5
Medium Priority
?
848 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

670 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