如何在索引库上使用循环 [英] How to use loop on index base

查看:88
本文介绍了如何在索引库上使用循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public void Mail(GridViewRow grid)
    {
        StringBuilder strEmail = new StringBuilder();
        //GridViewRow grid = GVEcDecision.Rows[0];
        GridView gvChild = (GridView)grid.FindControl("GVInspectorDetails");
        string StrInspector = string.Empty;
        Label lblInspector = null;
        string StrMobile = string.Empty;
        Label Mobile = null;
        if (gvChild != null)
        {

            foreach (GridViewRow row in gvChild.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    Label Lblcheck = (Label)row.FindControl("lblemail");
                    lblInspector = (Label)row.FindControl("LblName");
                    strEmail.Append("," + Lblcheck.Text);
                    string Inspectorname = Lblcheck.Text.ToString();
                    Mobile = (Label)row.FindControl("Mobile");

                    if (lblInspector != null)
                    {
                        StrInspector = lblInspector.Text;
                    }
                    if (Mobile != null)
                    {
                        StrMobile = Mobile.Text;

                    }
                    Label lblcollegename = (Label)grid.FindControl("lblcollegename");
                    Label lblinsptype = (Label)grid.FindControl("lblinsptype");
                    Label lblcoursespec = (Label)grid.FindControl("lblcoursespec");
                    string CollegeName = grid.Cells[4].Text;
                    string insptype = grid.Cells[5].Text;
                    string coursespec = grid.Cells[6].Text;
                    Label LblSubInspectionType = (Label)grid.FindControl("LblSubInspectionType");
                    Label lblfroseat = (Label)grid.FindControl("lblfroseat");
                    Label lblIncrSeat = (Label)grid.FindControl("lblIncrSeat");

                    string subinsptype = LblSubInspectionType.Text.ToString();
                    string FormSeat = lblfroseat.Text.ToString();
                    string toSeat = lblIncrSeat.Text.ToString();
                    TextBox txt1 = (TextBox)grid.FindControl("TxtEnddate");
                    string ToDate = txt1.Text.ToString();
                    TextBox txt2 = (TextBox)grid.FindControl("TxtStartdate");
                    string FormDate = txt2.Text.ToString();
                    Label lblstate = (Label)grid.FindControl("lblStatename");
                    string State = lblstate.Text.ToString();
                    Label lblcity = (Label)grid.FindControl("lblcity");
                    string city = lblcity.Text.ToString();

                    StringBuilder mailbody = new StringBuilder();
                    System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
                    string email = strEmail.ToString().Substring(1, strEmail.ToString().Length - 1);
                    string[] emailList = email.Split(',');
                    for (int j = 0; j <; emailList.Length; j++)
                   // foreach (string value in emailList)
                    {
                        
                        message.To.Add(new System.Net.Mail.MailAddress(emailList[j]));
                       
                      
                            message.Subject = "Appointment of Council's Inspectors";
                            message.Body = StrInspector + "," + city + "," + StrMobile + " <br> <br>This is Confirmation mail that You have been appointed for inspection as per Your "
                                                 + "availity after Telephonic Discussion.<br><br>" +
                                                 "Particulars for the inspection to be held as under:-<br>" +
                                                 " Course:-" + insptype + "<br>" +
                                                 " Purpose:-" + subinsptype + "<br>" +
                                                 " Seats:-" + toSeat + "<br>" +
                                                 " City:-" + city + "<br>" +
                                                 " State:-" + State + "<br>" +
                                                 " Date:-" + FormDate + "To" + ToDate + "<br> <br>" +
                                                 "You will get a Formal Letter from DCI including all details about the College to be inspected<br>" +
                                                 "before one day to inspection to be held through mail<br><br>" +
                                                 " The Dental Council of India has engaged M/s Balmer Lawrie & Co.Ltd., a Govt.of <br>" +
                                                 " India authorized travel partner to make bookings of air-tickets,hotel accommodation <br>" +
                                                 " and taxi for all the inspectors/Visitors of the Council while going on DCI inspection. <br>" +
                                                 " Therefore the said travel partner will contact you regarding your travel plan and will <br>" +
                                                 " make travel arrangements accordingly.in case of any query and clarification you may <br>" +
                                                 "contact the travel partner's representative Mr.Omprakash at 9899604205,011- <br>" +
                                                 "42524112 or E-mail:prakash.o@balmerlawrie.com & ridhi.s@vacationsexotica.com<br><br>" +
                                                 "<Now, you are requested to complete your preparation for the aforesaid inspection.in case<br>" +
                                                 "<of any query you may contact us: Contact No.011-23236544 & 9818189120 and E-mail us<br>" +
                                                 "<at:inspection@dciindia.org<br><br>" +
                                                 "Please acknowledge the receiving immediately by E-mail<br>" +
                                                 "reply on inspections@dciindia.org.<br><br><br>" +
                                                 "Thanking You<br><br>" +
                                                 "Secretary<br>" +
                                                 "Dental Council of India<br>" +
                                                 "New Delhi<br><br>" +
                                                 "Copy to:<br>" +
                                                 "Mr.Omprakash and Ms.Ridhi,M/s.Balmer Lawrie & Co.Ltd.for furtherance in the<br>" +
                                                 "matter.";
                        }

                        message.IsBodyHtml = true;
                        MailAddress fromAddress = new MailAddress("inspections@dciindia.org", "DCI");
                        message.From = fromAddress;
                        //added New
                        MailAddress copy = new MailAddress("inspections@dciindia.org");
                        message.CC.Add(copy);
                        //MailAddress copy1 = new MailAddress("prakash.o@balmerlawrie.com");
                        //message.CC.Add(copy1);
                        //MailAddress copy2 = new MailAddress("ridhi.s@vacationsexotica.com");
                        //message.CC.Add(copy2);
                        //End
                        SmtpClient smtp = new SmtpClient();
                        smtp.Host = "mail.dciindia.org";
                        //smtp.EnableSsl = true;
                        NetworkCredential credential = new NetworkCredential("inspections@dciindia.org", "getin@inspdci!1015");
                        smtp.Credentials = credential;
                        smtp.Port = 26;
                        smtp.Send(message);
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Mail has been Successfully send')", true);
                    }
                }
            }
        }





我尝试了什么:



以上是我的代码,它工作正常 -

i想知道我得到两个索引[0], [1]在电子邮件发送者中,所以我只能获得[1]索引的值,所以请帮助我



What I have tried:

above is my code and it is working fine -
i want to know i get two index [0],[1] in emaillist so what i do only get value of [1] index so please help me

推荐答案

你似乎试图做的是防止重复电子邮件外出 - 如果以前发过电子邮件发送到某个地址,请暂停此时间。



问题是这意味着您存储的信息是发送/未发送状态某处 - 以及使用GridView中的数据执行此操作的合理位置,因为除了会话之外,它是您唯一可以真正看到的地方。我建议您需要做的是更新Gridview数据的来源 - 可能是某种类型的数据库 - 包括一个电子邮件列,然后在您发送邮件时更新。

否则,如果用户打开一个包含相同数据的新页面,则会再次发送电子邮件。



首先查看您的数据源,以及它来自哪里from - 你需要在那里实现一些系统来防止这种情况以及添加到你显示的代码中的检查。我们看不到任何这些,所以我们无法给你精确的指示!
What you appear to be trying to do is to prevent duplicate emails going out - if an email has been sent to an address before, stop it going this time.

The problem is that that means you storing information on "sent / not-sent" status somewhere - and the logical place to do that it with the data in your GridView, as it's the only place that you can really look at, other than the Session. I'd suggest that what you need to do is update the source of your Gridview data - presumably it's a DB of some kind - to include an "emailed" column which you then update when you sent the mail.
Otherwise, if the user opens a new page with the same data the emails will be sent again.

So start by looking at your datasource, and where it comes from - you need to have some system implemented there to prevent this as well as checks added to the code you show. And we can't see any of that, so we can't give you precise instructions!


这篇关于如何在索引库上使用循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆