Tuesday, 21 April 2015

Css for Auto copleted extender

 .completionList {

        border:solid 1px yellow;

        margin:0px;

        padding:3px;

        height: 120px;

        overflow:auto;

        background-color: yellow;    

        }

        .listItem {

        color: yellow;

        }

        .itemHighlighted {

        background-color:yellow;      

        }


Cs File for Auto completed extender

 [System.Web.Services.WebMethod]
     public static List<string> searcharea(string prefixText, int count)
     {

         List<string> areaname = new List<string>();
         SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["galagoconnection"].ToString());
         if (conn.State == ConnectionState.Closed)
         {
             conn.Open();
         }
         SqlDataAdapter adp = new SqlDataAdapter("select Area_Name from G_Service_Area where Area_Name like '" + prefixText + "'+'%'", conn);
         DataTable dtService = new DataTable();
         adp.Fill(dtService);
         if (dtService != null && dtService.Rows.Count > 0)
         {
             foreach (DataRow dr in dtService.Rows)
             {
                 areaname.Add(dr["Area_Name"].ToString());
             }
         }


         return areaname;
     }  

 .Aspx for AutoCompleted extender
  <asp:TextBox ID="txtarea" runat="server" width="100%"></asp:TextBox>
                                <cc1:AutoCompleteExtender ServiceMethod="searcharea" CompletionListCssClass="completionList over"
    MinimumPrefixLength="1"
    CompletionInterval="100" EnableCaching="false" CompletionSetCount="10"
    TargetControlID="txtarea"
    ID="AutoCompleteExtender3" runat="server" FirstRowSelected = "false" >
</cc1:AutoCompleteExtender>

 

Monday, 13 April 2015

xml insert in sql

ALTER procedure [dbo].[sp_Mst_ReqField] --'I','<ROOT><SUBROOT><G_Id>5</G_Id><Cat_Id>171</Cat_Id><Vc_FieldName>Ad_Title</Vc_FieldName></SUBROOT></ROOT>'        
@Action VARCHAR(3)=NULL,        
@XmlValues varchar(max)
--@message varchar(100)=NULL output          
as          
  SET NOCOUNT ON            
declare @status int,@id int,@XmlData xml ,@XmlValue varchar(max)        

set @XmlValue=@XmlValues
SET @XmlData = CONVERT(XML,@XmlValue, 1);
select  @XmlData        
begin tran Mst_ReqField_tran          
set @status=0
         
if(@Action='I')          
 begin          


       
 DECLARE @TEMPReqMast AS TABLE      
(      
G_Id int,Cat_Id int,Vc_FieldName varchar(100) )      
INSERT INTO @TEMPReqMast                
SELECT      
 y.mytable1.value('G_Id[1]','int'),        
 y.mytable1.value('Cat_Id[1]','int'),                
 y.mytable1.value('Vc_FieldName[1]','varchar(100)')              
from @XmlData.nodes('//ROOT/SUBROOT') AS y (mytable1)
       
insert into Mst_ReqField(G_Id,Cat_Id,Vc_FieldName)    
select G_Id,Cat_Id,Vc_FieldName  from @TEMPReqMast
 if(@@error<>0)          
  set @status=100          
 --if(@@error=0)          
 -- --Set @message='Banner details saved successfully'          
 --else          
 -- Set @message='Banner creation failure due to' + @status          
         
end    
       
if(@status<>0)              
begin              
 rollback tran Mst_ReqField_tran              
end              
else              
begin            
    commit Tran Mst_ReqField_tran            
end              

Monday, 6 April 2015

Fill Gridview with parameters


Class file Code .cs


public void FillGridprocedure(string SPName, string[] objParams, object[] objValues, GridView gv)
        {
            _objConnection = this.GetConnection();
            _objCommand = new SqlCommand(SPName, _objConnection);
            _objCommand.CommandType = CommandType.StoredProcedure;
            for (int i = 0; i < objParams.Length; i++)
            {
                _objParameter = new SqlParameter(objParams[i], objValues[i]);
                _objCommand.Parameters.Add(_objParameter);
            }

            _objConnection.Open();
            SqlDataAdapter objDataAdapter1 = new SqlDataAdapter(_objCommand);
            DataTable _objDataTable1 =new DataTable();
            objDataAdapter1.Fill(_objDataTable1);
            _objConnection.Close();
            if (_objDataTable1 != null && _objDataTable1.Rows.Count > 0 && _objDataTable1.Rows[0][0].ToString() != null)
            {
                gv.DataSource = _objDataTable1;
            gv.DataBind();
            }else
            {
                gv.EmptyDataText="No Record Found ......";
            }
        }


In ButtonClick Event

 protected void btnsearch_Click(object sender, EventArgs e)
    {
        string[] Parameter = { "@V_name", "@Phone_No", "@City", "@Service_Area" };
        string[] Values = { txtvendor.Text, txtmobile.Text, txtcity.Text, txtservice.Text };
        objDatalayer.FillGridprocedure("Sp_SearchVendor", Parameter, Values, GridView1);

    }



Friday, 3 April 2015

How to Add AutoComplete Ajax extender in Asp.net


aspx source code

 <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<div>
                    <asp:TextBox ID="txtcityname" runat="server"></asp:TextBox>

                     <cc1:AutoCompleteExtender ServiceMethod="Akramsrch"
    MinimumPrefixLength="2"
    CompletionInterval="100" EnableCaching="false" CompletionSetCount="10"
    TargetControlID="txtcityname"
    ID="AutoCompleteExtender1" runat="server" FirstRowSelected = "false">
</cc1:AutoCompleteExtender>
   
                  </div>


cs -View Code 

namespace:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Web.Services;

source Code

  [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
  
    public static List<string> Akramsrch(string prefixText, int count)
    {
        SqlConnection con = new SqlConnection("server=SOFTNET-AKRAM;database=zizlee;uid=sa;pwd=12345;");
       
       {
      
            using (SqlCommand cmd = new SqlCommand())
            {
                cmd.CommandText = "select City_Name from dbo.G_Service_Area where " +
                "City_Name like @SearchText + '%'";
                cmd.Parameters.AddWithValue("@SearchText", prefixText);
                cmd.Connection = con;
                con.Open();
                List<string> customers = new List<string>();
                using (SqlDataReader sdr = cmd.ExecuteReader())
                {
                    while (sdr.Read())
                    {
                        customers.Add(sdr["City_Name"].ToString());
                    }
                }
              
                return customers;
            }

        }
     

    }



Thursday, 2 April 2015

Less Secure Apps



Some apps and devices use less secure sign-in technology, which makes your account more vulnerable. You can turn off access for these apps, which we recommend, or turn on access if you want to use them despite the risks. Learn more

https://www.google.com/settings/security/lesssecureapps

First Login your gmail A/c



1.Open the above link on another tab

        Less Secure Apps(This page is appear)
3.Access for less secure apps --Turn On.
 

Send email from Gmail with SMTP authentication but got "5.5.1 Authentication Required" error

1. Please make sure you have set SMTP authentication correctly in your script, for sample code, please click here

2. If there is no problem with your SMTP script, but you still got the message message mentioned above, it should because Gmail blocked the authentication from our server as it detected that it is the first time you login to your Gmail account from another Country or Location. You will need to login to gmail security center to approve the authntication. Once you approved it , please wait a few minutes then sending email from script again. Here are the steps to approve the "Unusual activity alerts" from gmail security center.
a) go to gmail security center via this link blow or google search for "gmail secrity" and login with your gmail account
https://accounts.google.com/ServiceLogin?elo=1
b) next to "security" / "Recent activity" , click to "view all events"
c) You will able to see "Unusual Activity" , it will show all unusual activity events, select related event and approval it via click " Yes, That was me!"

3.d)In the "Security"/"Account permission", click to the "Settings" button to enable the "Access for less secure apps".



Wednesday, 1 April 2015

How to bind temporary row in table by switch case statement

 Project.aspx

<asp:DataList ID="imagelist" runat="server" RepeatColumns="4">
                       <ItemTemplate>
                           <table>
                               <tr>
                                   <td style="text-align:left;">
                                       <a href="<%#Eval("reflink") %>" target="_blank"><asp:Image ID="Image1" runat="server" Height="146px" ImageUrl='<%# Eval("photo") %>' Width="190px"/></a>
                                   </td>
                               </tr>
                               <tr>
                                   
                                   <td style="text-align:center;">
                                       <asp:Label ID="lblprname" runat="server" Text='<%# Eval("Project_Name") %>'></asp:Label>
                                   </td>
                               </tr>
                           </table>
                       </ItemTemplate>


                   </asp:DataList>














project.cs


protected void Page_Load(object sender, EventArgs e)
    {
 if (!IsPostBack)
        {
grdload();

}


}















public void grdload()
    {

        DataTable dt = objDataLayer.FillDataTable("select Project_Name,photo,reflink from CR_HotProperty where dflag='0' and photo!=''");
       
       
        int count = dt.Rows.Count;

        DataTable dtnew = new DataTable();
        dtnew.Columns.Add("photo");
        dtnew.Columns.Add("Project_Name");
        dtnew.Columns.Add("reflink");
        foreach (DataRow drdt in dt.Rows)
        {
            DataRow drdtnew = dtnew.NewRow();
            drdtnew["photo"] = drdt["photo"].ToString();
            drdtnew["Project_Name"] = drdt["Project_Name"].ToString();
            drdtnew["reflink"] = drdt["reflink"].ToString();
            dtnew.Rows.Add(drdtnew);

        }



        switch (count)
        {
            case 0:
                for (int i = 0; i < count + 4; i++)
                {
                    DataRow drnew = dtnew.NewRow();
                    drnew["photo"] = "~/images/No-image.jpg";
                    drnew["Project_Name"] = "No Porject Available";
                    drnew["reflink"] = "";
                    dtnew.Rows.Add(drnew);
                    imagelist.DataSource = dtnew;
                    imagelist.DataBind();

                }
                break;
            case 1:
                {
                    for (int i = 1; i <= 3; i++)
                    {
                        DataRow drnew = dtnew.NewRow();
                        drnew["photo"] = "~/images/No-image.jpg";
                        drnew["Project_Name"] = "No Porject Available";
                        drnew["reflink"] = "";
                        dtnew.Rows.Add(drnew);
                        imagelist.DataSource = dtnew;
                        imagelist.DataBind();


                    }
                    break;
                }
            case 2:
                for (int i = 1; i <= 2; i++)
                {
                    DataRow drnew = dtnew.NewRow();
                    drnew["photo"] = "~/images/No-image.jpg";
                    drnew["Project_Name"] = "No Porject Available";
                    drnew["reflink"] = "";
                    dtnew.Rows.Add(drnew);
                    imagelist.DataSource = dtnew;

                    imagelist.DataBind();

                }
                break;

            case 3:
                {
                    for (int i = 1; i <= 1; i++)
                    {
                        DataRow drnew = dtnew.NewRow();
                        drnew["photo"] = "~/images/No-image.jpg";
                        drnew["Project_Name"] = "No Porject Available";
                        drnew["reflink"] = "";
                        dtnew.Rows.Add(drnew);
                        imagelist.DataSource = dtnew;

                        imagelist.DataBind();

                    }
                    break;

                }
            case 4:
                {
                    imagelist.DataSource = dt;
                    imagelist.DataBind();

                }
                break;
        }
        foreach (DataListItem items in imagelist.Items)
        {
            Image img = (Image)items.FindControl("Image1");
            if (dtnew.Rows[0]["reflink"].ToString() == null || dtnew.Rows[0]["reflink"].ToString() == "")
            {
                img.ToolTip = "No Link Found";
            }
            else
            {
                img.ToolTip = dt.Rows[0]["reflink"].ToString();
            }
           
        }









    }