Solved

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

Posted on 2011-02-11
5
845 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

735 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