Monday, 6 February 2017

PRINT WEB PAGE IN PDF USING JAVASCRIPT IN ASP.NET C#

By using this function, can print page which is reside in any table. This method will print all things in PDF format.


<script language="javascript" type="text/javascript">

function PrintPageDetail() {

var printContent = document.getElementById('<%= tblGrd.ClientID %>');// TableName 
var printWindow = window.open("All Records", "Print Panel",     'left=50000,top=50000,width=0,height=0');
printWindow.document.write(printContent.innerHTML);
printWindow.document.close();
printWindow.focus();
printWindow.print();

}

</script>

Call above function like this:

<asp:Button ID="btnPrint" runat="server" Text="Print Record(s)" OnClientClick="PrintPageDetail()"/>

Sunday, 18 September 2016

Show list of items with searchable keyword at runtime (as a dropdown list) using textbox with the help of AjaxTool in Asp.net C#

STEP 1:

   First of all add ajaxTool element in codebehind of program.

Take a textbox as shown below and then add the AjaxToolKit element with this textbox.


<asp:TextBox ID="txtCatgrySerch" runat="server" OnTextChanged="txtCatgrySerch_TextChanged"></asp:TextBox>

<ajaxToolkit:AutoCompleteExtender runat="server" ID="AutoCompleteExtender1" TargetControlID="txtCatgrySerch"
MinimumPrefixLength="1" CompletionInterval="100" EnableCaching="false" CompletionSetCount="10"
FirstRowSelected="false" ServiceMethod="GetName" />


Instruction To Use:

 Write the TextBox id in TargetControlID and the Method Name That showing Below in ServiceMethod as shown above.

STEP 2:

public partial class Form_XYZ : System.Web.UI.Page
{
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<string> GetName(string prefixText)
{
dbConnection cn = new dbConnection();
cn.CreateObject();
using (MySqlDataAdapter adp = new MySqlDataAdapter("ProcedureName", ConnectionString))
{
List<string> E_NAME2 = new List<string>();
adp.SelectCommand.CommandType = CommandType.StoredProcedure;
adp.SelectCommand.Parameters.AddWithValue("@SearchItem", prefixText);
DataTable dt = new DataTable();
adp.Fill(dt);
for (int i = 0; i < dt.Rows.Count; i++)
{
E_NAME2.Add(dt.Rows[i][0].ToString());
}
return E_NAME2;
}
}
}


Instruction To Use:
a)      Make Procedure for searching records from specific table on any condition.
b)      In this method Typed keyword will automatically pass in this method and will show the result.
c)       Important Note: Inside this method any server control will not work, you will unable to see the controls. In this case you can add HttpContext.Current.Session["AnyName"] for maintaing Session or anything else.

RESULT :


Wednesday, 10 August 2016

Convert Image to byte array and byte to image in ASP.NET C#

Convert Image to byte and then display in Asp.Net C#:

Suppose you are facing problem in showing image from folder to asp.net Image control. Then use below code to display image instant.

Reason behind using this code:

Suppose you have images in folder and path in database. then just pass path in this code and it will get image from folder using this path and then first it will convert into byte and then will directly assign to display to the image control

e.g:

System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath(@"C:/FolderName/abc.jpg"));
                            byte[] bytes;
                            using (MemoryStream ms = new MemoryStream())
                            {
                                img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                                bytes = ms.ToArray();                            
                            }
                            string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
                            Image1.ImageUrl = "data:image/png;base64," + base64String;
                            img.Dispose();


Convert image from Fileupload to byte and then display in ASP.Net C#

Reason behind using this code:

Suppose you want to upload new image to replace existing image then due to postback effect system does not show the new
image. In that case below code will first convert image into byte then assign to imageurl

e.g:

string imgType = System.IO.Path.GetExtension(FUploadImg.FileName);
                    int imgSize = FUploadImg.PostedFile.ContentLength;
                 
                    byte[] imgbyte = new byte[imgSize];
                    HttpPostedFile img = FUploadImg.PostedFile;
                    img.InputStream.Read(imgbyte, 0, imgSize);

string base64String = Convert.ToBase64String(imgbyte, 0, imgbyte.Length);
Image2.ImageUrl = "data:image/png;base64," + base64String;



                         
                            

Sunday, 12 April 2015

CREATE DYNAMIC COLUMNS IN DATAGRIDVIEW IN ASP.NET C#

Suppose you have a gridview and you want to create multiple columns dynamically in asp.net c#. In this case first you have take a datatable and insert the name of header dynamically. After this procees assign the columns to gridview control. Now you can see the result. Please follow following example.

DataTable dt = new DataTable();
DataTable dt1 = new DataTable();

TemplateField xtemplt = new TemplateField();
BoundField xbound = new BoundField();
grdview2.AutoGenerateColumns = false;

          Xbound.HeaderText = "PersonName";
           Xbound.DataField = "PersonName";
                grdview2.Columns.Add(bfield);

MySqlDataAdapter da;
xquery = "SELECT city_name FROM city ";
da = new MySqlDataAdapter(xquery, dbConn);
da.Fill(dt1);              

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

                    dt.Columns.Add("myrow", typeof(string));
                    dt.Columns[i + 1].ColumnName = dt1.Rows[i].ItemArray[0].ToString();
                                  (OR)                  
                    dt.Columns["myrow"].ColumnName = "NewDelhi";


                    xtemplt = new TemplateField();
                    xtemplt.HeaderText = dt1.Rows[i].ItemArray[0].ToString();
               

                    grdview2.Columns.Add(xtemplt);

                }

  dt.Columns.Add("myrow", typeof(string));
                dt.Columns["myrow"].ColumnName = "TOTAL";            

                bfield = new BoundField();
                bfield.HeaderText = "TOTAL";
                bfield.DataField = "TOTAL";
                grdview2.Columns.Add(bfield);

               grdview2.DataSource = dt;
                grdview2.DataBind();

after calling this function RowdataBound method will call . When program will reach to gridview2 .databind()  then rowdatabound will called. In this below code you can change the column behaviour like assigning the textbox for adding values, linkview button, dropdown, listbox etc.


        protected void grdview2_RowDataBound(object sender, GridViewRowEventArgs e)
        {


            if (e.Row.RowType == DataControlRowType.DataRow)
            {

                for (int i = 1; i < grdview2.Columns.Count ; i++)
                {
                    TextBox txtcells = new TextBox();
                    txtcells.ID = "txtcells";

                    string xcolnam = grdview2.Columns[i].HeaderText.ToString();
         txtcells.Text = (e.Row.DataItem as    DataRowView).Row[xcolnam].ToString();
                    e.Row.Cells[i].Controls.Add(txtcells);

                }


/* You can also change the particular column in Linkview Mode using Specified Index */

                LinkButton lnkview = new LinkButton();
                lnkview.ID = "lnkview";

                lnkview.Click += new EventHandler(lnkview_Click);

                lnkview.Text = (e.Row.DataItem as DataRowView).Row[0].ToString();
               lnkview.CommandArgument = (e.Row.DataItem as DataRowView).Row[0].ToString();
                e.Row.Cells[0].Controls.Add(lnkview);


            }


        }

MYSQL CONNECTION STRING IN ASP.NET C# INSIDE WEB.CONFIG AND WEB PAGES



<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>
  <connectionStrings>

<add name="connstring" connectionString="Database=databaseName;DataSource=localhost;UserId=xzy;Password=abc123;Allow zero datetime= true;"providerName="MySql.Data.MySqlClient"/>

 </connectionStrings>
</configuration>


After Using this above code you can call this in any for directly Please see below code

namespace form1

{
    public partial class form1 : System.Web.UI.Page
    {
        MySqlConnection dbConn = new MySqlConnection(ConfigurationManager.ConnectionStrings["connstring"].ConnectionString);

}

Dbconn=new MySqlConnection();

}


Wednesday, 5 February 2014

Top 12 Android Tablet In India

Apple iPAD2
Apple iPad2 has been launched in India and it is a remarkable device. Apple iPad2 is faster, sleeker and lighter in weight. It using iOS 5 operating system and with over 2,000,00 apps designed exclusively for the iPad. The price of Apple 16GB ipad2 with wi-fi is approx 24199 in india.

ACER Iconia A500
ACER Iconia A500 one of the best tablet in Indian market. It using Android Honeycomb with 10-inch capacitive LCD (1024 X 1280 pixel resolution), 1GHz dual-core NVIDIA Tegra 2 processor, 1GB RAM, 5 megapixel primary camera with auto focus with LED Flash, the front camera has 2 megapixel facility for video calling, upto 8 hours battery life, support up to 32GB microSD card, 1080p HD video playback, HDMI port and Dolby mobile surround sound.


Its price in India: Rs 27,500

HCL ME AE7-A1
This is one of the best selling android tablet in low price in India. HCL ME AE7-A1 key Features:
Android 2.2 with 7-inch resistive touchscreen (800 X 480 pixel) resolution, 800MHz processor, 256MB RAM, 2GB in-built Flash Memory and 0.3 megapixel front camera for video calling, WiFi connectivity, EVDO USB Dongle support, USB 2.0 port and It can support microSD Card up to 8GB.

Its price In India market: Rs 14,990


HCL ME AP10A-A1
HCL ME AP10A-A1 run on Android 2.2 FroYo. It has 10 inch capacitive touchscreen display with (1024 X 600 pixel) resolution. It has fast speed due to its 1GB RAM supporting system. This tablet has wide storage area due to its 16GB in-built storage features. It has connectivity including both connection like WiFi and 3G. Its other key features like 1.3 megapixel camera, Full HD 1080p video playback, GPS, Mini USB port, microSD card that can support upto 32GB.

Its price in India: Rs 32,990


HCL ME AM7-A1
HCL ME AM7-A1 also run on Android 2.2 FroYo. It has 7-inch capacitive touchscreen display with (1024 X 600 pixel) resolution, 512MB RAM facility, in-built storage with 8GB memory space, WiFi and 3G connectivity, GPS, Full HD 1080p video playback, 1.3 megapixel camera, mini USB port, microSD card that can support up to 16GB.

Its price in India: Rs 25,790

ViewPad 10
ViewPad 10 run on Dual-Boots Android 1.6 and Windows 7 Home Premium. It has one of the best display screen with 10 inch backlit LED display (1024 X 600 WVGA resolution), 1.66GHz Intel pine Trail Processor, 1GB DDR3 RAM, 200mHz Intel GFX GPU, 16GB SSD, 2 USB 2.0 port, WiFi connectivity, Mini VGA port and microSD card support up to 32GB.

Its Price in India:Rs 38,000


VIEWSONIC VIEWPAD-7
ViewSonic Viewpad 7 runs on Android 2.2 FroYo with its 7 inch TFT display (800 X 480 WVGA) resolution, 600MHz Qualocmm MSM7227 processor, 512MB NAND Flash Memory, WiFi connectivity, 512MB SD RAM, GPS and A-GPS, SIM card Slot, microSD card support up to 32GB and Mini USB port

Its price in India: Rs 31,000

Notion Ink Adam
Notion Ink Adam launched in three different combination. It run on Android 2.2 FroYo (upgraded to Android 2.3 Gingerbread), It has 1GHz Dual-core Cortex A9 processor, ULP GPU, 3.2 megapixel autofocus swivel camera, 2 USB 2.0 ports, 10.1 inch pixelQi Display with Matte Coating (1024 X 600 pixel) resolution, mini USB port, SIM card slot, HDMI out, 8GB in-built Flash Memory and up to 32GB supported MicroSD Card.
Its Price According to its combination:

Normal LCD WiFi - Rs 21,999
Normal LCD WiFi + 3G - Rs 24,999
PixelQi screen, WiFi + 3G - 29,999


OlivePad VT100

OlivePad VT100 run on Android 2.2, It has wide display of 7 inch TFT with (800 X 400 WVGA) resolution, 600MHz Qualcomm MSM7227 processor, 3 megapixel camera with autofocus, front facing camera, voice and video calling, 3G connectivity, 512MB internal Memory, MicroSD card that can support up to 32GB, mini USB port, 3240mAh Li-Po battery, MayMyIndia with lifetime subscription.

Its price in India: Rs 16,990 to 23,000


Samsung Galaxy Tab
Samsung Galaxy Tab run on Android 2.2 (upgradable to Android 2.3), 7-inch Gorilla Glass Display with (600 X 1024 pixel) resolution, 1GHz Cortex A8 processor, PowerVR SGX540 GPU, 1.3 megapixel facing camera and 3.15 megapixel primary camera with autofocus and LED Flash, Flash 10.1 supported, Full HD Video playback, mini USB port and microSD card support up to 32GB, 16/32GB variants, TV-out.

Its price in India: Rs 25,000 to Rs 38,000

Dell Streak5

Dell Streak 5 initially comes in Android 1.6 but you can upgrade this to Android 2.2. It has 5 inch Gorilla Glass Display with (480 X 800 pixel) resolution, its internal storage is 16GB and external microSD card can support up to 32GB, 1GHz Qualcomm Scorpion processor, Adreno 200 GPU, 1530 mAh Li-ion battery, Dual-LED Flash and 5 megapixel camera with autofocus, 720p video recording with Android Eclair/FroYo update and A-GPS system.

Its price in India: Rs 24,500 to Rs 34,990

Binatone HomeSurf MID
Binatone HomeSurf MID is one of the low pricing and efficient android tablet in market for those who can't effort high range tablets. This device run on Android 1.6 and it has 8-inch resistive LCD touchscreen (800 X 600 pixel) resolution, WiFi connectivity, 128MB DDR RAM, 2GB NAND Flash Memory, mini USB port, MicroSD card slot and 3000 mAh Li-ion battery. It can be beneficial for students for study and using at home for kids etc.
 
Its price in India: Rs 9000