This is a migrated thread and some comments may be shown as answers.

Sending Email from Radgrid

6 Answers 421 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Prathap Narravula
Top achievements
Rank 1
Prathap Narravula asked on 15 Sep 2010, 05:35 PM

Hi please help me in this issue,

I have a RadGrid with employee details.  If i select multiple employees through checkbox column, i have to send email to all the checkbox selected employees when i click on the sendemail button.

Need quick response.

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 16 Sep 2010, 06:04 AM
Hello Prathap,

In order to achieve this, in Button_Click event of sendemail button loop through each grid item and find all the selected CheckBox and corresponding email id of selected employees. Check out the following sample code .

ASPX:
<Columns>
.........
<telerik:GridTemplateColumn UniqueName="CkhSelect" HeaderText="Select">
  <ItemTemplate>
    <asp:CheckBox ID="chkbxselect" runat="server" />
  </ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="UserMailID" HeaderText="MailId" UniqueName="MailID">
</telerik:GridBoundColumn>
.......
</Columns>

<asp:Button ID="BtnSendMail" runat="server" onclick="Button5_Click" Text="SendMail" />

C#:
protected void BtnSendMail_Click(object sender, EventArgs e)
   {
       foreach(GridDataItem  item in RadGrid1.Items) //loop through each grid item
       {
           CheckBox chkSelected = (CheckBox)item.FindControl("chkbxselect");
           if (chkSelected.Checked)
           {
               string mail = item["MailID"].Text; // accessing email id of each selected employees
            
           }
    }

Hope this helps,
Princy.
0
Prathap Narravula
Top achievements
Rank 1
answered on 20 Sep 2010, 08:50 AM
Dear Princy,

Thanks for the above code. I am getting all the email id's through checkboxes selection. Now i have to send email to all the selected employees.
 
Can u please provide me the code for sending email to the selected employees when i click on sendbutton itself for multiple employees

Need quick response.
waiting for reply

Regards,
Prathap
0
Princy
Top achievements
Rank 2
answered on 20 Sep 2010, 11:03 AM
Hello Prathap,

Please refer the following link which explains how to send email.

Send out email in code behind (C#)
Code to send email
Sending Email through ASP. NET

Hope this helps,
Princy.
0
Justin
Top achievements
Rank 1
answered on 01 Sep 2011, 08:34 PM
Hi Princy,

I gave your code a try and for some reason it always returns false for my checkboxes, any ideas?

This is my grid:
<telerik:radgrid id="grdLeadList" runat="server" autogeneratecolumns="false" allowpaging="True"
    allowsorting="True" pagesize="5" allowautomaticupdates="true" gridlines="None"
    allowmultirowselection="true" onitemcommand="grdLeadList_ItemCommand" DataKeyNames="opportunityid" style="float: left; width: 965px;">
<ExportSettings HideStructureColumns="true" >
    <Excel Format="ExcelML" />
    <Csv ColumnDelimiter="Comma" RowDelimiter="NewLine" />
    <Pdf />
</ExportSettings>
<PagerStyle Mode="NextPrevNumericAndAdvanced" />
<MasterTableView Width="100%" TableLayout="Auto"  >
    <CommandItemSettings ShowExportToExcelButton="false" ShowExportToCsvButton="false" ShowExportToPdfButton="false" ShowAddNewRecordButton="false" />
    <Columns>
        <telerik:GridTemplateColumn UniqueName="CkhSelect" HeaderText="Select">
          <ItemTemplate>
            <asp:CheckBox ID="chkbxselect" runat="server" />
          </ItemTemplate>
        </telerik:GridTemplateColumn>
        <telerik:GridEditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit" />
        <telerik:GridBoundColumn DataField="CustomerId" HeaderText="Company Name" SortExpression="CompanyName" UniqueName="CompanyName" />
        <telerik:GridBoundColumn DataField="Priority" HeaderText="Priority" SortExpression="Priority" UniqueName="Priority" />
        <telerik:GridBoundColumn DataField="Eval" HeaderText="Eval" SortExpression="Eval" UniqueName="Eval" />
        <telerik:GridBoundColumn DataField="ContactName" HeaderText="Contact Name" SortExpression="ContactName" UniqueName="ContactName" />
        <telerik:GridBoundColumn DataField="Source" HeaderText="Source" SortExpression="Source" UniqueName="Source" />
        <telerik:GridBoundColumn DataField="State" HeaderText="State" SortExpression="State" UniqueName="State" />
        <telerik:GridNumericColumn DataField="Zip" HeaderText="Zip" SortExpression="Zip" UniqueName="Zip" />
        <telerik:GridDateTimeColumn DataField="CreatedOn" DataFormatString="{0:MM/dd/yy}" HeaderText="Creation Date" SortExpression="CreationDate" UniqueName="CreationDate" />
    </Columns>
    <EditFormSettings UserControlName="LeadShareEditPanel.ascx" EditFormType="WebUserControl">
        <EditColumn UniqueName="EditCommandColumn1" />
    </EditFormSettings>
</MasterTableView>
<ClientSettings EnableRowHoverStyle="false" >
    <Selecting AllowRowSelect="True"  />
</ClientSettings>
</telerik:radgrid>

and this is my code behind:
 protected void imgBtnSendRecords_Click(object sender, ImageClickEventArgs e)
 {
     string mail = "";
 
     foreach (GridDataItem item in grdLeadList.Items) //loop through each grid item
     {
         CheckBox chkSelected = (CheckBox)item.FindControl("chkbxselect");
         if (chkSelected.Checked == false)
         {
             mail = mail + item["Priority"].Text + " ";
 
         }
     }
}

Thanks!
0
Shinu
Top achievements
Rank 2
answered on 02 Sep 2011, 06:00 AM
Hello Justin,

Check the condition likeif (chkSelected.Checked)  which is true on checking  the Checkbox.

Thanks,
Shinu.
0
Justin
Top achievements
Rank 1
answered on 02 Sep 2011, 03:24 PM
Thanks for the reply!

I got it working by moving it to OnInit and it works good. The only problem is the checkboxes don't clear after the Send button is clicked. Anyway around that?

Thanks!
Tags
Grid
Asked by
Prathap Narravula
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Prathap Narravula
Top achievements
Rank 1
Justin
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or