protected void btn_daily_send_all_Click(object sender, EventArgs e)
{
int flag = 0;
gvAllClients.Visible = true;
gvAllClients.AllowPaging = false;
try
{
if ((txt_daily_from.Text != "") || (txt_daily_to.Text != ""))
{
string strSucessEmail = "";
string strFailedEmail = "";
DateTime date_from_for_daily_email = Convert.ToDateTime(txt_daily_from.Text);
DateTime date_to_for_daily_email = Convert.ToDateTime(txt_daily_to.Text);
DateTime date_end = Convert.ToDateTime(ViewState["latest_date_port_uploaded"]);
DateTime dt = Convert.ToDateTime(ViewState["date_last_mailed"]);
DateTime date_start = choosing_first_date(ref dt);
foreach(GridViewRow row in gvAllClients.Rows)
{
string strworkOrder = ((Label)(row.Cells[5].FindControl("lblWorkOrd"))).Text;
string strdata = ((Label)(row.Cells[6].FindControl("lblData"))).Text;
string strHSCODE = ((Label)(row.Cells[9].FindControl("lblHSCode"))).Text;
string strCombination = ((Label)(row.Cells[10].FindControl("lblComb"))).Text;
string strProd = ((Label)(row.Cells[11].FindControl("lblProd"))).Text;
string strProd_Not = ((Label)(row.Cells[12].FindControl("lblProd_not"))).Text;
string strActive = ((Label)(row.Cells[13].FindControl("lblActive"))).Text;
string strEmailId = ((Label)(row.Cells[14].FindControl("lblEmail"))).Text;
DateTime date_from_subscp = Convert.ToDateTime(((Label)(row.Cells[7].FindControl("lblfrom"))).Text);
DateTime date_to_subscp = Convert.ToDateTime(((Label)(row.Cells[8].FindControl("lblTo"))).Text);
CheckBox chk = (CheckBox)(row.Cells[30].FindControl("chkEmail_Single"));
if (strActive == "NO")
{
strFailedEmail += "" + strEmailId + ", ";
}
else if (strActive == "YES")
{
if (date_to_for_daily_email > date_end)
{
lblMsg.Visible = true;
lblMsg.Text = "You cannnot select a date less than last mailed date and greater than " + date_end.ToString("dd-MMM-yyyy") + ".";
}
else if (date_from_for_daily_email > date_to_for_daily_email)
{
lblMsg.Visible = true;
lblMsg.Text = "Invalid date range. Please check the dates and than try again...";
}
else if (date_to_subscp < date_to_for_daily_email)
{
strFailedEmail += "" + strEmailId + ", ";
}
else if (chk.Checked == true)
{
strFailedEmail += "" + strEmailId + ", ";
}
else
{
int iResult = bl_Query_for_admin.Query_Data_Email_Attachment(strworkOrder, strdata, date_from_for_daily_email, date_to_for_daily_email, strHSCODE, strCombination, strProd, strProd_Not, strEmailId);
if (iResult == 1)
{
if (flag == 0)
{
bl_myAccount.insert_last_daily_email_date(date_to_for_daily_email);
flag = 1;
}
strSucessEmail += "" + strEmailId + ", ";
lblMsg.Visible = true;
lblMsg.Text = "Email Sent Succesfully !!!";
continue;
}
else
{
continue;
}
}
}
}
btnLog.Visible = true;
gvAllClients.Visible = true;
inserting_mail_history(ref strSucessEmail, ref strFailedEmail);
}
else
{
lblMsg.Visible = true;
lblMsg.Text = "Please enter a valid date for data mining...";
}
}
catch (Exception ex)
{
}
}
I have binded my gv outside the postback ryt now Sir...