Tuesday, 29 October 2013

Social Sites Share Button for website Floating Left using javascript

Copy & Paste this code to your website:

 <!-- AddThis Button BEGIN -->

<div class="addthis_toolbox addthis_floating_style addthis_counter_style" style="left:50px;top:180px;">
<a class="addthis_button_facebook_like" <%="fb:like:layout"%>="box_count" width="70px"></a>
<a class="addthis_button_tweet" tw:count="vertical"></a>
<a class="addthis_button_google_plusone" g:plusone:size="tall"></a>
<a class="addthis_counter"></a>
</div>
<script type="text/javascript">var addthis_config = {"data_track_addressbar":true};</script>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-526f51334345dc15"></script>


<!-- AddThis Button END -->

Saturday, 26 October 2013

Change Div/Panel Border width and color on dropdownlist selectedchanged Event using Javascript

Use this code to implement this function:

<asp:DropDownList ID="ddlchnageborderwidth" runat="server">
          <asp:ListItem Value="1px">1px</asp:ListItem>
          <asp:ListItem Value="2px">2px</asp:ListItem>
          <asp:ListItem Value="3px">3px</asp:ListItem>
          <asp:ListItem Value="4px">4px</asp:ListItem>
</asp:DropDownList>
                                             
<asp:DropDownList ID="ddlchnagebordercolor" runat="server">
         <asp:ListItem Value="#000000">Black</asp:ListItem>
         <asp:ListItem Value="#0000FF">Blue</asp:ListItem>
         <asp:ListItem Value="#A52A2A">Brown</asp:ListItem>
         <asp:ListItem Value="#FF7F50">Coral</asp:ListItem>
         <asp:ListItem Value="#A9A9A9">DarkGray</asp:ListItem>
        <asp:ListItem Value="#8B0000">DarkRed</asp:ListItem>
 </asp:DropDownList>


Color change javascript code:
<script type="text/javascript">
$("#ddlchnageborderwidth").change(function() {
    $("#someDiv").css("border-width", $(this).val());
}).change();
 </script>

                                                ​
Color change javascript code:
<script type="text/javascript">
$("#ddlchnagebordercolor").change(function() {
    $("#someDiv").css("border-color", $(this).val());
}).change();
 </script>

Add Facebook Like and Share Button API to Website

Copy & Paste this code for Facebook like button with count:

<div id="fb-root"></div>
<script type="text/javascript">(function(d, s, id) 
{
   var js, fjs = d.getElementsByTagName(s)[0];
   if (d.getElementById(id)) return;
   js = d.createElement(s); js.id = id;
   js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
   fjs.parentNode.insertBefore(js, fjs);
}
(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-like" data-href="http://brijeshsolutions.blogspot.com" data-send="false" data-layout="button_count" data-width="200" data-show-faces="false"></div>



Copy & Paste this code for Facebook Share button with count:

<div style='float:center;padding:0px 0px 0px 25px'>
<a share_url='http://brijeshsolutions.blogspot.com' href='http://www.facebook.com/sharer.php'  name='fb_share' type='button_count' target="_blank">Share Brijesh Solutions< /a><script src='http://static.ak.fbcdn.net/connect.php/js/FB.Share' type='text/javascript'></script>

</div>

Thursday, 24 October 2013

How to Use a Windows Installer Disc to Back Up Your Files When Your Computer Won’t Boot



back-up-files-from-windows-cd
If Windows won’t boot, recovering your files can be a headache.  You do n0t have to pull the hard drive or use a Linux live CD – you can use a Windows installer disc to quickly back up your files.
We have included steps for both Windows 8 and Windows 7 here – the process is basically the same on each.  You can use a Windows 7 disc to back up files from a Windows 8 system or vice versa.

Boot From a Windows Installer Disc

First, insert a Windows installer disc (or a USB drive with the Windows installer on it) into your computer and restart your computer.  If everything is working properly, you will see a “Press any key to boot from CD or DVD” message.  Press a key to enter the installer.  If you do not see this screen, you may need to change the boot settings in your computer’s BIOS.
Click the Next option and select Repair Your Computer.  You will see this option at the bottom-left corner of the window, whether you are using a Windows 7 or Windows 8 installer disc.
If you are using a Windows 8 installer disc, select Troubleshoot > Advanced Options > Command Prompt.
If you are using a Windows 7 installer disc, select the Restore your computer using a system image you created earlier option, click Next, click Cancel, and click Cancel again.
You will see the System Recovery Options window – click Command Prompt to launch a Command Prompt window.
When you see a Command Prompt, type notepad and press Enter to launch a Notepad window.  Click File and select Open in the Notepad window.
Ensure you select the All Files option at the bottom of the window, and then click the Computer option.
You can use this Open dialog as if it were a Windows Explorer window – select files and you’ll be able to copy and paste them elsewhere.  If you connect a USB drive or removable hard drive to your computer, you will be able to copy-paste files onto it.
Do not double-click any files or Notepad will try to open them, possibly freezing.  If Notepad freezes on you, go back to the Command Prompt window and type taskmgr to launch the Task Manager.  You can end the frozen Notepad task and re-launch Notepad.
Once you are done copying your files off your hard drive, you can close the windows and shut down your computer.  Or, if you plan on reinstalling Windows anyway, you can now begin performing a clean installation with your files safely backed up.

Wednesday, 23 October 2013

Open New Window as Popup with defined size on Button Click using C#

Use this Code on button click event:

ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", "var Mleft = (screen.width/2)-(760/2);var Mtop = (screen.height/2)-(700/2);window.open( 'popup.aspx', null, 'height=500,width=560,status=yes,toolbar=no,scrollbars=yes,menubar=no,location=no,top=\'+Mtop+\', left=\'+Mleft+\'' );", true);

Tuesday, 8 October 2013

ASP.NET - Export Gridview data to excel and directly send a mail with exported excel file

On Control Event use this code in C#:

                        GridView gdvExportxls = new GridView();
                        gdvExportxls.DataSource = dtnew;
                        gdvExportxls.DataBind();
                        MemoryStream ms = new MemoryStream();
                        System.IO.StringWriter stringWriter = new System.IO.StringWriter();
                        System.Web.UI.HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
                        gdvExportxls.RenderControl(htmlWriter);
                        byte[] excelFile = System.Text.Encoding.ASCII.GetBytes(stringWriter.ToString());
                        ms.Write(excelFile, 0, excelFile.Length);
                        ms.Position = 0;

                        Attachment attachment = new Attachment(ms, "Test.xls", "application/vnd.xls");
                        SendMail(attachment);


          private void SendMail(Attachment excel)
        {
            MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
            mail.From = new MailAddress("brijesh.singh879@gmail.com")
            mail.Subject = "Export GridView to Excel";
            mail.Body = "mail with attachment";

            //System.Net.Mail.Attachment attachment;
            //attachment = excel;
            mail.Attachments.Add(excel);

            SmtpServer.Port = 587;
            SmtpServer.Credentials = new System.Net.NetworkCredential("brijesh.singh879@gmail.com", "*******");
            SmtpServer.EnableSsl = true;
            SmtpServer.Send(mail);

        }

Saturday, 5 October 2013

GridView Select all row using Header Checkbox or select one row using checkbox in C#.NET

Copy and Paste this code to .aspx Page :

<asp:GridView ID="GridView1" runat="server" Width="100%" BackColor="White" BorderColor="White"
                                BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1" GridLines="None"
                                AutoGenerateColumns="False" Style="font-size: 10pt">
                                <RowStyle BackColor="#DEDFDE" ForeColor="Black" />
                                <PagerStyle BackColor="#669900" ForeColor="White" Font-Bold="true" />
                                <HeaderStyle BackColor="#669900" Font-Bold="True" ForeColor="#E7E7FF" />
                                <Columns>
                                    <asp:TemplateField HeaderText="Course" HeaderStyle-HorizontalAlign="Left">
                                        <ItemTemplate>
                                            <asp:Label ID="id" runat="server" Text='<%#Eval("Row_Id")%>' Visible="false"></asp:Label>
                                            <asp:Label ID="lblgrade" runat="server" Text='<%#Eval("Quali1")%>'></asp:Label>
                                        </ItemTemplate>
                                        <HeaderStyle HorizontalAlign="Left" />
                                        <ItemStyle Width="35px" />
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Grade" HeaderStyle-HorizontalAlign="Left">
                                        <ItemTemplate>
                                            <asp:Label ID="lblsubgrade" runat="server" Text='<%#Eval("Quali2")%>'></asp:Label>
                                        </ItemTemplate>
                                        <HeaderStyle HorizontalAlign="Left" />
                                        <ItemStyle Width="45px" />
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Roll No" HeaderStyle-HorizontalAlign="Left">
                                        <ItemTemplate>
                                            <asp:Label ID="lblroll" runat="server" Text='<%#Eval("RollNo")%>'></asp:Label>
                                        </ItemTemplate>
                                        <HeaderStyle HorizontalAlign="Left" />
                                        <ItemStyle Width="80px" />
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Name" HeaderStyle-HorizontalAlign="Left">
                                        <ItemTemplate>
                                            <asp:Label ID="lblName" runat="server" Text='<%#Eval("Name")%>'></asp:Label>
                                        </ItemTemplate>
                                        <HeaderStyle HorizontalAlign="Left" />
                                        <ItemStyle Width="180px" />
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Father's Name" HeaderStyle-HorizontalAlign="Left">
                                        <ItemTemplate>
                                            <asp:Label ID="lblfname" runat="server" Text='<%#Eval("FName")%>'></asp:Label>
                                        </ItemTemplate>
                                        <HeaderStyle HorizontalAlign="Left" />
                                        <ItemStyle Width="180px" />
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Date" HeaderStyle-HorizontalAlign="Left">
                                        <ItemTemplate>
                                            <asp:Label ID="lbldate" runat="server" Text=""></asp:Label>
                                        </ItemTemplate>
                                        <HeaderStyle HorizontalAlign="Left" />
                                        <ItemStyle Width="70px" />
                                    </asp:TemplateField>
                                    <asp:TemplateField>
                                        <ItemTemplate>
                                            <asp:CheckBox ID="cbxap" runat="server" AutoPostBack="true" OnCheckedChanged="cbxap_CheckedChanged" />
                                        </ItemTemplate>
                                        <HeaderTemplate>
                                            A/P<asp:CheckBox ID="cbxapall" runat="server" AutoPostBack="true" OnCheckedChanged="cbxapall_CheckedChanged" />
                                        </HeaderTemplate>
                                        <ItemStyle Width="50px" />
                                    </asp:TemplateField>
                                </Columns>

                            </asp:GridView>


and .cs Page Code is given:

Bind GridView:
private void bindgridview()
        {
            try
            {
                DataTable dt = app.GetDataTable("select * from tb_Regstd_mst where Center='" + ddlcenter.SelectedItem.Text + "' and Quali1='" + ddlgrade.SelectedItem.Text + "' and Quali2='" + ddlsubgrade.SelectedItem.Text + "' order by RollNo Asc");
                GridView1.DataSource = dt;
                GridView1.DataBind();
                foreach (GridViewRow gv in GridView1.Rows)
                {
                    Label date = (Label)gv.FindControl("lbldate");
                    date.Text = DateTime.Now.ToShortDateString();
                }
                if (GridView1.Rows.Count <= 0)
                {
                    btnattd.Visible = false;
                    lblmsg.Text = "No Student Records Found in this Category.";
                }
                else
                {
                    lblmsg.Text = "";
                    btnattd.Visible = true;
                }
            }
            catch (Exception)
            {

            }

        }


On Header Checkbox checkchanged Event :
protected void cbxapall_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                CheckBox chkH = (CheckBox)GridView1.HeaderRow.FindControl("cbxapall");
                if (chkH.Checked == true)
                {
                    foreach (GridViewRow gv in GridView1.Rows)
                    {
                        CheckBox chk = (CheckBox)gv.FindControl("cbxap");
                        chk.Checked = true;
                    }
                }
                else
                {
                    foreach (GridViewRow gv in GridView1.Rows)
                    {
                        CheckBox chk = (CheckBox)gv.FindControl("cbxap");
                        chk.Checked = false;
                    }

                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }

        }


Checkchanged event of each row :
protected void cbxap_CheckedChanged(object sender, EventArgs e)
        {
            bool isFound = false;
            CheckBox cbxall = (CheckBox)GridView1.HeaderRow.FindControl("cbxapall");
            foreach (GridViewRow gvr in GridView1.Rows)
            {
                CheckBox chkSelect = gvr.FindControl("cbxap") as CheckBox;
                if (chkSelect.Checked == false)
                {
                    isFound = true;
                    break;
                }

            }

            if (isFound)
                cbxall.Checked = false;
            else
                cbxall.Checked = true;

        }

Friday, 4 October 2013

Play Youtube video with URL in C#.NET

Copy and paste this code on C# code file


                    string youtubeUrl = "http://www.youtube.com/watch?v=6rpZnBfG6YE";

                    string vCode = youtubeUrl.Substring(youtubeUrl.LastIndexOf("v=") + 2);
                    if (vCode.Contains("&"))
                        vCode = vCode.Substring(0, vCode.LastIndexOf("&"));

                    string sHtml = @"<object width='{0}' height='{0}' data='http://www.youtube.com/v/{2}&autoplay=0' codetype='application/x-shockwave-flash'>
                           &ltparam name='movie' value='http://www.youtube.com/v/{2}&autoplay=0'></param></object>";
                    //define frame size
                    string sWidth = "200px";
                    string sHeight = "100px";

                    video.GroupingText = String.Format(sHtml, sWidth, sHeight, vCode);

where video is the Id of Div/Panel