Pages

Friday 17 February 2012

Multiple Column Filter Using Asp.Net with C#

Here I will explain Multiple Column Filter Using Asp.Net with C#.

//passing querystring with fields
if (items == string.Empty)
            {
                if (GvList.Rows.Count > 0)
                {
                    clcnt = GvList.Columns.Count;
                    shipal.Clear();
                    for (int i = 1; i < clcnt - 2; i++)
                    {
                        if (i != 7)
                        {
                            shipal.Add(GvList.HeaderRow.Cells[i].Text);
                        }
                    }
                    items = string.Empty;
                    items = String.Join(",", ((string[])shipal.ToArray(typeof(String))));
                }
            }
            ImgFilter.Attributes.Add("onclick", "window.showModalDialog('Filter.aspx?" + EncryptQueryString(string.Format("QString={0}", items"','','dialogWidth:400px;dialogHeight:400px;center:yes;edge:raised;resizable:no;scroll:off;status:yes')");


//.aspx code
  <table>
        <tr>
            <td colspan="2">
                <asp:Panel ID="pnl" runat="server" BorderColor="LightGray" Width="385px" Height="300px"
                    ScrollBars="Auto">
                    <asp:GridView ID="gvfilter" runat="server" AutoGenerateColumns="False" Width="367px"
                        Font-Names="Tahoma" Font-Size="8pt" CellPadding="4" ForeColor="#333333" BackImageUrl="~/Assets/img/tab9.png"
                        HeaderStyle-Height="30px">
                        <HeaderStyle CssClass="GridViewHeaderStyle" />
                        <Columns>
                            <asp:TemplateField HeaderText="Field">
                                <ItemTemplate>
                                    <asp:DropDownList ID="ddlfilter" runat="server" Width="125px" Font-Names="Tahoma"
                                        Font-Size="8pt">
                                    </asp:DropDownList>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Filter">
                                <ItemTemplate>
                                    <asp:TextBox ID="txtfilter" runat="server" Width="200px" BackColor="#F7F6F3" BorderStyle="None"
                                        Font-Names="Arail" Font-Size="8pt"></asp:TextBox>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                </asp:Panel>
            </td>
        </tr>
        <tr>
            <td align="right" class="style1">
            </td>
            <td class="style1">
            </td>
        </tr>
        <tr>
            <td align="right">
                <asp:Button ID="BtnOk" runat="server" OnClick="BtnOk_Click" Text="OK" Font-Names="Arial"
                    Width="75px" Font-Size="8pt" />
                &nbsp;
                <asp:Button ID="BtnCancel" runat="server" Font-Names="Arial" Font-Size="8pt" Width="75px"
                    Text="Cancel" OnClientClick="window.close();" />
            </td>
        </tr>
    </table>


//.cs code
if (Request.QueryString["QString"] != null)
                {
                    if (!string.IsNullOrEmpty(QString))
                    {
                        string[] arry = Request.QueryString["QString"].ToString().Split(',');
                        gvfilter.DataSource = arry;
                        gvfilter.DataBind();
                        foreach (string item in arry)
                        {
                            foreach (GridViewRow row in gvfilter.Rows)
                            {
                                ddl = (DropDownList)row.FindControl("ddlfilter");
                                ddl.Items.Add(item);
                            }
                        }
                        foreach (GridViewRow row in gvfilter.Rows)
                        {
                            ddl = (DropDownList)row.FindControl("ddlfilter");
                            ddl.Items.Insert(0, "");
                        }
                    }
                }


//ok button

protected void BtnOk_Click(object sender, EventArgs e)
[

for (int i = 0; i < gvfilter.Rows.Count; i++)
{

ddl = (
DropDownList)gvfilter.Rows[i].FindControl("ddlfilter");

txt = (TextBox)gvfilter.Rows[i].FindControl("txtfilter");

al.Add(ddl.SelectedValue);

alfltr.Add(txt.Text);

}

string items = String.Join(",", ((string[])al.ToArray(typeof(String))));

string fltrs = String.Join(",", ((string[])alfltr.ToArray(typeof(String))));

Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "A", "<script>window.returnValue = true;window.close();</script>");

if (SList != null)

{

Session[
"fil1"] = al;

Session["txtfil1"] = alfltr;

}

else

{

Session[
"fil"] = al;

Session["txtfil"] = alfltr;

}

 

}

Monday 16 January 2012

Sendig mail with attachement using asp.net


Sending Mail through Asp.Net


Common and important aspect used in Web designing is email sending. Basic use of sending email from a Web page is to enable the users to give their comments/suggestions through web form. The .NET Framework provides extremely straightforward means to send emails. ASP .NET makes use of SmtpMail and MailMessage classes to send an emaill. The SmtpMail and MailMessage classes are defined in the System.Web.Mail namespace. The MailMessage class has properties and methods for creating an email and the SmtpMail class has send method to send an email.

public bool SendingMail(string fromAddress,string toAddress,string subject,string bodymessage,string[] fileattachement)
{
try

{MailAddress mailfrom = new MailAddress(fromAddress);
MailAddress mailto = new MailAddress(toAddress);
MailMessage newmsg = new MailMessage(mailfrom, mailto);
newmsg.Subject = subject;
newmsg.Body = bodymessage;
////For File Attachment, more file can also be attached
foreach (var files in fileattachment)
{Attachment att = new Attachment(files);

newmsg.Attachments.Add(att);
}
//Configure the smtp Address
SmtpClient smtps = new SmtpClient("smtp.gmail.com", 587);
smtps.UseDefaultCredentials = false;//passing the Network credentials
smtps.Credentials = new NetworkCredential("mail@gmail.com", "pwd");

//passing ssl
smtps.EnableSsl = true;

smtps.Send(newmsg);return true;

}catch (Exception ex)

{return false;

}

}

On Button Click

bool Status = SendingMail(txtfromAddress.Text, txttoAddress.Text, txtsubject.Text, txtbodymessage.Text, files);

if (Status)
lblEmailStatus.Text =
"your mail has been sent successfully";
else
lblEmailStatus.Text = "sorry! your mail not sent successfully";

 

Wednesday 4 January 2012

Get the value between two strings in c#.net


Here I will explain find to get the value between two strings in c#.net

private static string result;
string st = @"<err:Description>Ship web service is currently unavailable sdfsssssssssssssss.</err:Description></err:PrimaryErrorCode></err:ErrorDetail></err:Errors>";
string findfrom = "<err:Description>";
string findto = "</err:Description>";
string orival = betweenval(st, findfrom, findto);

private static string betweenval(string src, string findfrom, string findto)
{
int start = src.IndexOf(findfrom);
int to = src.IndexOf(findto, start + findfrom.Length);
if (start < 0 || to < 0)
    return "";
else
    result = src.Substring(start + findfrom.Length, to - start - findfrom.Length);
return result;
}