简体   繁体   English

获取一行asp.net gridview onclick的值并发送电子邮件

[英]get values of a row of asp.net gridview onclick and send email

as u can see from below aspx code i need values of row of the gridview 正如你从下面的aspx代码中看到的那样,我需要gridview的行的值

1)My gridview last column contains dropdownlist.it contains two values (qualified/disqualifed).on selecting qualified or disqaulified i need to get all the values of the row of gridview.... 1)我的gridview的最后一列包含dropdownlist.it包含两个值(限定/不合格)。在选择合格或不合格时,我需要获取gridview行的所有值....

2)after getting all the values i need to send those values to email...the email should be send to the particular email id of email column, 2)获取所有值后,我需要将这些值发送到电子邮件...电子邮件应发送到电子邮件列的特定电子邮件ID,

For eg-if i select 1st row from gridview.and in that 1st row if i select ist dropdownlist(either qualified/disqualified).after selecting qualified/disqualified from dropdownlist i need to get all the values of the first row..and i need to send all the values of the first row of gridviews through email to the emai id of first row..... 例如,如果我从gridview中选择第一行,并且如果我选择ist dropdownlist(合格/不合格),则在该第一行中。从dropdownlist选择合格/不合格后,我需要获取第一行的所有值。需要通过电子邮件将gridviews第一行的所有值发送到第一行的emai ID。

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
       BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px"
       CellPadding="4" CellSpacing="2" ForeColor="Black" Height="122px"
       Width="495px" onrowdatabound="GridView1_RowDataBound">
       <FooterStyle BackColor="#CCCCCC" />
       <RowStyle BackColor="White" />
       <Columns>
           <asp:BoundField HeaderText="Application No" DataField="appno" />
           <asp:BoundField HeaderText="Name" DataField="appname" />
           <asp:BoundField HeaderText="Company Name" DataField="cname" />
           <asp:BoundField HeaderText="Post Name" DataField="pname" />
           <asp:BoundField HeaderText="Email" DataField="email" />
           <asp:BoundField HeaderText="Mobile No" DataField="mobile" />
           <asp:BoundField DataField="mksobtain" HeaderText="Marks Obtain" />
           <asp:BoundField DataField="mkstot" HeaderText="Total Marks" />
           <asp:BoundField DataField="hrname" HeaderText="HR Name" />
           <asp:BoundField DataField="hrno" HeaderText="HR No" />
           <asp:TemplateField HeaderText="Qualification Process">
               <EditItemTemplate>
                   <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
               </EditItemTemplate>
               <ItemTemplate>
                   <asp:Label ID="Label1" runat="server"></asp:Label>
                   <asp:DropDownList ID="DropDownList1" runat="server" 
              AutoPostBack="True" >
                   </asp:DropDownList>
               </ItemTemplate>
           </asp:TemplateField>
       </Columns>
       <PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
       <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
       <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
   </asp:GridView>

To trigger the email, you need to either use the SelectedIndexChanged event of the drop down list or add a Send Email button to the grid view markup and handle the click event for that button or create a CommandName attribute. 要触发电子邮件,您需要使用下拉列表的SelectedIndexChanged事件或将“ Send Email按钮添加到网格视图标记并处理该按钮的click事件或创建CommandName属性。 This choice determines how you will get the row you want to get the values from. 此选择确定如何获取要从中获取值的行。

Because you are using BoundField s in your grid view markup, you will need to reference the values of the row via the Cells collection of the row, like this: 因为在网格视图标记中使用BoundField ,所以需要通过该行的Cells集合来引用该行的值,如下所示:

// Assuming you have the row object, either from e.Row or 
// finding the parent or grandparent of the click event sender
GridViewRow theGridViewRow;

// Get the application number value
string theApplicationNumber = theGridViewRow.Cells[0].Text;

// Do similar logic for each field you want the value of here

Instead of depending upon the index value of the Cells collection, I recommend you use TemplateField s in your grid view markup, like this: 建议您不依赖于Cells集合的索引值,而建议在网格视图标记中使用TemplateField ,如下所示:

<Columns>
    <asp:TemplateField HeaderText="Application No">
        <asp:Label id="LabelApplicationNumber" runat="server" 
                   Text="<%# Eval('appno') %>" />
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Name">
        <asp:Label id="LabelApplicationName" runat="server" 
                   Text="<%# Eval('appname') %>" />
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Company Name">
        <asp:Label id="LabelCompanyName" runat="server" 
                   Text="<%# Eval('cname') %>" />
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Post Name">
        <asp:Label id="LabelPostName" runat="server" 
                   Text="<%# Eval('pname') %>" />
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Email">
        <asp:Label id="LabelEmail" runat="server" 
                   Text="<%# Eval('email') %>" />
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Mobile No">
        <asp:Label id="LabelMobileNumber" runat="server" 
                   Text="<%# Eval('mobile') %>" />
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Marks Obtain">
        <asp:Label id="LabelMarksObtain" runat="server" 
                   Text="<%# Eval('mksobtain') %>" />
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Total Marks">
        <asp:Label id="LabelTotalMarks" runat="server" 
                   Text="<%# Eval('mkstot') %>" />
    </asp:TemplateField>
    <asp:TemplateField HeaderText="HR Name">
        <asp:Label id="LabelHRName" runat="server" 
                   Text="<%# Eval('hrname') %>" />
    </asp:TemplateField>
    <asp:TemplateField HeaderText="HR No">
        <asp:Label id="LabelHRNumber" runat="server" 
                   Text="<%# Eval('hrno') %>" />
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Qualification Process">
        <EditItemTemplate>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        </EditItemTemplate>
        <ItemTemplate>
            <asp:Label ID="Label1" runat="server"></asp:Label>
            <asp:DropDownList ID="DropDownList1" runat="server" 
                              AutoPostBack="True" >
            </asp:DropDownList>
        </ItemTemplate>
    </asp:TemplateField>
</Columns>

Now in your code-behind, you can use the FindControl() method to get the values from the row instead of using the Cells[i] notation, like this: 现在,在代码隐藏中,您可以使用FindControl()方法从行中获取值,而不是使用Cells[i]表示法,如下所示:

// Assuming you have the row object, either from e.Row or 
// finding the parent or grandparent of the click event sender
GridViewRow theGridViewRow;

// Find the application number label control in the row
var theApplicationNumberLabel = theGridViewRow.FindControl("LabelApplicationNumber") as Label;

// Make sure we found the label before we try to use it
if(theApplicationNumberLabel != null)
{
    // Get the value
    string theApplicationNumber = theApplicationNumberLabel.Text;
}

// Do similar logic for each control in the row you want the value of here

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM