Click here to Skip to main content
15,921,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Dear ,,

I have question about Send GridView select Row popup as email body on Button click in ASP.Net vb ...

ASP.NET
<div style="text-align: center; margin-bottom: 10px; font-size: 20px; color: brown"><asp:Label ID="lblmsg" runat ="server" ></div>
 
<asp:GridView ID="GridView1" runat="server" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
    AutoGenerateColumns="false" OnSelectedIndexChanged = "OnSelectedIndexChanged">
    <columns>
 
       Columns Here ...
 
         
                <asp:ButtonField Text="Select" CommandName="Select" />
 
    
       

 
        <asp:LinkButton Text="" ID = "lnkFake" runat="server" />
<cc1:modalpopupextender id="mpe" runat="server" popupcontrolid="pnlPopup" targetcontrolid="lnkFake" cancelcontrolid="btnClose" backgroundcssclass="modalBackground">

<asp:Panel ID="pnlPopup" runat="server" CssClass="modalPopup" Style="display: none">
    <div class="header">
        Details
    </div>
     
 
         <div class="body">
 
              <asp:TextBox ID="TextBoxName" runat="server" placeholder="Your Name"   style="width: 126px;
    float: left;
    height: 25px;
    border: 1px solid;
    border-color: #c4c4c4 #d1d1d1 #d4d4d4;
    border-radius: 2px;
    outline: 2px solid #eff4f7;
    color: #404040;
    padding: 0 10px;">
              <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ValidationGroup="A"
                        ControlToValidate="TextBoxName" ErrorMessage="Required field">
 
      <asp:TextBox ID="TextBoxEmail" runat="server" placeholder="Email Address"   style="width: 126px;
    float: left;
    height: 25px;
    border: 1px solid;
    border-color: #c4c4c4 #d1d1d1 #d4d4d4;
    border-radius: 2px;
    outline: 2px solid #eff4f7;
    color: #404040;
    padding: 0 10px;">
                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBoxEmail"
                        ErrorMessage="Format Email Error" ValidationGroup="A" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">
                
             <br>
      <asp:TextBox ID="TextBoxNots" runat ="server" placeholder="Nots" TextMode ="MultiLine" rows="4" style="width: 282px;
    float: left;
    margin-left: 7px;
    border: 1px solid;
    border-color: #c4c4c4 #d1d1d1 #d4d4d4;
    border-radius: 2px;
    outline: 2px solid #eff4f7;
    color: #404040;
    padding: 0 10px;"><br>
              <asp:Button ID="Button1" runat ="server"  Text="Rigester"  CommandName="Select" style="width: 267px;
    float: left;
    margin-left: 7px;
    border-radius: 2px;
    height: 29px;
    border: 1px solid;margin-top: 3px;" />
 
             </div>
 
         <div class="footer" align="right">
        <asp:Button ID="btnClose" runat="server" Text="Close" CssClass="button" />
    </div>


VB Code :

VB
Protected Sub OnSelectedIndexChanged(sender As Object, e As EventArgs)
 
        
        Dim TextBoxName As String = GridView1.SelectedRow.Cells(0).Text
        Dim TextEmail As String = GridView1.SelectedRow.Cells(1).Text
        Dim TextNots As String = GridView1.SelectedRow.Cells(2).Text
        mpe.Show()
 
        Dim body As String = "Name:" + TextBoxName + "<br>" + "Email:" + TextEmail + "<br>" + "Nots:" + TextNots
        Dim mail As New MailMessage()
        mail.[To].Add("noor@gmail.com")
        mail.Bcc.Add("noor@gmail.com")
        mail.From = New MailAddress("noor@gmail.com")
        mail.Subject = "New Register Member ...." + Name
        mail.Body = body
        mail.IsBodyHtml = True
 
        Dim smtp As New SmtpClient("relay-hosting.secureserver.net")
        smtp.EnableSsl = False
        smtp.UseDefaultCredentials = True
        smtp.Send(mail)
 
        lblmsg.Text = "registration successful"


What I have tried:

When I send the data in the pop-up window .. send an empty data for Emile , Like:

Name :
Email :
Msg :

How do I solve the problem ?!
Posted
Updated 27-Nov-16 23:01pm

1 solution

Hi,

I think, you are trying its correct.But
C#
GridView1.SelectedRow.Cells(0).Text
This line we generally use to access
<asp:BoundField

which are dataField mentioned in gridview got it??

As you are declared div and textboxes under it. I am not sure but you can try like this to access name, email etc
(GridView1.SelectedRow.FindControl("TextBoxName") as TextBox).Text;
 
Share this answer
 
Comments
[no name] 28-Nov-16 5:20am    
OK,i'm using vb.net language ,

when i try this code :
Dim TextBoxName As String = TryCast(GridView1.SelectedRow.FindControl("TextBoxName"), TextBox).Text

This code works only when taking into gridview columns like :

<asp:TemplateField HeaderText="Days" ItemStyle-Width="150">
<itemtemplate>
....





But when I put it in a pop-up window, as illustrated in the above code sends empty for email !
preety sunita 28-Nov-16 6:16am    
ohk left it..

Have a look may its useful link for you

Here is modalpopupextender is using for edit..and get filled data in method.

http://www.aspsnippets.com/Articles/Add-Edit-Update-Records-in-GridView-using-Modal-Popup-in-ASP.Net.aspx
[no name] 23-Oct-17 3:44am    
Thank you very much and I'm sorry because I was late in answering you ..
Your answer helped me .. Thank you alot ..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900