Wednesday, December 26, 2018

Autogenerate ID

using System.Configuration;
using System.Data;
using System.IO;


protected void generatedStudID()
    {
        con.Open();

        cmd = new SqlCommand("select MAX(Sr_No) from  TABLENAME", con);

   
        int i = Convert.ToInt32(cmd.ExecuteScalar());
        con.Close();
        i++;
        strID = ID + Year + z + i.ToString();


    }

Saturday, December 15, 2018

Solve DNS NOT Found problem in local system

1. Go to control panel

2. Click here Network and sharing center

3. Click Access Type Local Area Connection

4.Go to property

5. Select  4( TCP / IPV4 )

6. Set DNS 

                      8    8  8  8
                      8    8  4  4

Sunday, December 9, 2018

CHECL IMAGE URL IS NULL OR NOT

 <div id="Div1" runat="server" visible='<%# Eval("pic") != DBNull.Value %>'>
 
  <asp:Image ID="Image1"     ImageUrl='<%# "/pic/" + Eval("pic") %>' runat="server" style="height:355px; width: 486px;"></asp:Image>

  </div> 

Blog code in asp.net c#

ASPX CODE

 <style>
* {
    box-sizing: border-box;
}

/* Add a gray background color with some padding */
body {
    font-family: Arial;
    padding: 20px;
    background: #f1f1f1;
}

/* Header/Blog Title */
.header {
    padding: 30px;
    font-size: 40px;
    text-align: center;
    background: white;
}

/* Create two unequal columns that floats next to each other */
/* Left column */
.leftcolumn { 
    float: left;
    width: 75%;
}

/* Right column */
.rightcolumn {
    float: left;
    width: 25%;
    padding-left: 20px;
}

/* Fake image */
.fakeimg {
    background-color: #aaa;
    width: 100%;
    padding: 20px;
}

/* Add a card effect for articles */
.card {
     background-color: white;
     padding: 20px;
     margin-top: 20px;
}

/* Clear floats after the columns */
.row:after {
    content: "";
    display: table;
    clear: both;
}

/* Footer */
.footer {
    padding: 20px;
    text-align: center;
    background: #ddd;
    margin-top: 20px;
}

/* Responsive layout - when the screen is less than 800px wide, make the two columns stack on top of each other instead of next to each other */
@media screen and (max-width: 800px) {
    .leftcolumn, .rightcolumn { 
        width: 100%;
        padding: 0;
    }
}
</style>





   <div class="container bgwhite" style="border-top: 10px solid #4f6584;">
      <div class="row"  style="padding: 50px 0 30px 0;" >
   
 <div class="card">



   
         <asp:Repeater ID="Repeater1" runat="server">
   
    <ItemTemplate >   

      <h2> <asp:Label ID="Label2" runat="server" Text='<%# Eval ("title") %>' style="width: 486px;"></asp:Label></h2><br /> 


       <div id="Div1" runat="server" visible='<%# Eval("pic") != DBNull.Value %>'>
 
  <asp:Image ID="Image1"     ImageUrl='<%# "/pic/" + Eval("pic") %>' runat="server" style="height:355px; width: 486px;"></asp:Image>

  </div> 


      <br />

     <p>  <asp:Label ID="Label3" runat="server" Text='<%# Eval ("article") %>'>'></asp:Label>   </p>
 

   <hr />
 
    </ItemTemplate>

    </asp:Repeater>


     </div>
 </div></div>



CS CODE


       SqlCommand cmd = new SqlCommand("select * from TABLE ORDER BY id  DESC ", con);
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);
            Repeater1.DataSource = ds;
            Repeater1.DataBind();
         
               














Thursday, November 29, 2018

How to use OL tag in Repeater control

How to use  OL  tag in Repeater control




 <ol>
               <asp:Repeater ID="repearter" runat="server">
                    <ItemTemplate>
                     <a href='/publish/<%#Eval("filename") %>'>
                        <li>
                       
                      <span class="auto-style2" style="color:#333"><b>    <%# DataBinder.Eval(Container.DataItem, "title")%> </b> </span>  <br />

                        <asp:Label ID="lblTitle" runat="server" Text='<%# Eval("authorname") %>'></asp:Label>
                       
                       
                       
                        </li>
                        </a>
                        <br />
                         <hr /><br />
                    </ItemTemplate>
                </asp:Repeater>

        </Ol>

Thursday, November 1, 2018

Data list with column

 <asp:DataList ID="dlstmovie" runat="server" 
 RepeatColumns="4"   
 RepeatDirection="Horizontal" 
 Width="100%"
  CellPadding="4"
  CellSpacing="4" 
  OnItemCommand="dlstmovie_ItemCommand">

 <ItemTemplate>
     
     
 <asp:Label ID="Label3" runat="server" Visible="false" Text='<%#Eval("pyear") %>'>'> 

 </asp:Label>


 <asp:Button ID="but1" runat="server"   Width="114px"  CommandName="but1_Click"

  CssClass="contact-form"   Text='<%#Eval("pyear") %>'/>
                     
     
    </ItemTemplate>




c# code




  protected void show()
    {
       
        cn = new SqlConnection(cs);
        cn.Open();

        cm = new SqlCommand("select  pyear from publishtb group by pyear  ORDER BY pyear asc", cn);
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(cm);
        da.Fill(ds);

        dlstmovie.DataSource = ds;
        dlstmovie.DataBind();
        cn.Close();





    }

Gridview Image Link


 <asp:TemplateField HeaderText="View Certificate" >
                        <ItemTemplate>
                            <a onclick="javascript:window.open('<%# String.Format("/portal/upload/{0}",Eval("certificate")) %>','PORTAL','left=20,top=20,width=500,height=500,toolbar=0,reizable=0');" target="_blank">
                                Show
                            </a>
                        </ItemTemplate>

                    </asp:TemplateField>

Friday, October 19, 2018

Desktop Sharing

AeroAdmin

Listbox count program

protected void Button3_Click(object sender, EventArgs e)
    {
       

        if (DropDownList1.Items.Count > 1)
        {

            if (DropDownList1.SelectedIndex >= 15)
            {

            }
            else
            {
                DropDownList1.SelectedIndex = DropDownList1.SelectedIndex + 1;
            }


  }

Auto Generate Number Gridview


         <asp:TemplateField HeaderText="Sno">
         
        <ItemTemplate>
             <%#Container.DataItemIndex+1 %>
        </ItemTemplate>
    </asp:TemplateField>

Thursday, October 11, 2018

Manage Linkbutton inside Gridview

Aspx  Design



  <asp:TemplateField HeaderText="Reviewer Report" ItemStyle-CssClass="hs1" ItemStyle-Width="20px">

 <ItemTemplate> 
                 
<asp:ImageButton ID="lnk_report" runat="server" Visible="false"    CommandName="Select" ImageUrl="../images/editicon.png" OnClick="lnk_report_click"  />

  </ItemTemplate>
   </asp:TemplateField>



c#  code

protected void report()
    {

        //report button activation code

        string statusname;
        string cs = ConfigurationManager.ConnectionStrings["key"].ToString();
        cn = new SqlConnection(cs);
        cn.Open();

        foreach (GridViewRow r1 in dgvGrid.Rows)
        {
            dr.Close();

             Label lbid = (Label)r1.FindControl("LBLID");

             ImageButton lnk1 = (ImageButton)r1.FindControl("lnk_report");
           

             string k = "select * from table  where ID='" + lbid.Text + "'";
            cmd = new SqlCommand(k, cn);
            dr = cmd.ExecuteReader();
            while(dr.Read())
            {

                statusname = dr[6].ToString();

                if (statusname == "APPROVE")
                {

                    lnk1.Visible = true;
                }
             

            }
       


        }
        dr.Close();





    }

Tuesday, October 9, 2018

Create director on Run Time

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
public partial class rundirectory : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)// create
button show
    {
        Directory.CreateDirectory(Request.MapPath(TextBox1.Text) + "/");
        ListBox1.Items.Add(TextBox1.Text);
    }
    protected void Button2_Click(object sender, EventArgs e)//file uplad
    {
        FileUpload1.SaveAs(Server.MapPath("~")+"//"+ListBox1.Text+"//"+FileUpload1.FileName);
        Image1.ImageUrl = "~/" + ListBox1.Text + "/" + FileUpload1.FileName;
    }

}

Live Visitor Count on website

create globle.asx file

<%@ Application Language="C#" %>

<script runat="server">

    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup

        Application["hitcount"] = 0;

    }

    void Application_End(object sender, EventArgs e)
    {
        //  Code that runs on application shutdown

    }

    void Application_Error(object sender, EventArgs e)
    {
        // Code that runs when an unhandled error occurs

    }

    void Session_Start(object sender, EventArgs e)
    {
        // Code that runs when a new session is started
        int n;
        n = (int)Application["hitcount"];
        n = n + 1;
        Application["hitcount"] = n;


    }

    void Session_End(object sender, EventArgs e)
    {
        // Code that runs when a session ends.
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is
set to StateServer
        // or SQLServer, the event is not raised.

        int n;
        n = (int)Application["hitcount"];
        n = n - 1;
        Application["hitcount"] = n;

    }

</script>




How to call visitor


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class currentcount : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       //actual browsers open count(visiters)
        Label1.Text = "Number of Users is to be visited:=   " +
Application["hitcount"];

    }
}

Auto Redirect Page

Auto Redirect Page

<head runat="server">
  

    <meta http-equiv="refresh" content="2; URL=http://www.facebook.com"/>


    <meta name="keywords" content="automatic redirection"/>


   
</head>

Sunday, October 7, 2018

Display Gridview Cell Value on Button click event

 <asp:TemplateField HeaderText="Assign Reviewer" ItemStyle-CssClass="hs1" ItemStyle-

   Width="20px">

               <ItemTemplate> 


                   <asp:ImageButton ID="lnk_Update" runat="server"   CommandName="Select"

                    ImageUrl="../images/editicon.png"  OnClick="lnk_Update_Click" />

   </ItemTemplate>
   </asp:TemplateField>



C#  Code

  protected void lnk_Update_Click(object sender, EventArgs e)

    {

         var closeLink = (Control)sender;

        GridViewRow row = (GridViewRow)closeLink.NamingContainer;


        Label5.Text  = row.Cells[5].Text; // here we are


}

Monday, October 1, 2018

Gridview Linkbutton Event without using SelectedIndexChanged Event

Setting following Property in Gridview 

 <asp:GridView ID="dgvGrid" runat="server"  CssClass="mydatagrid" HeaderStyle-

   BackColor="#EEEEEE"  Width="100%" AutoGenerateColumns="False">


 <asp:TemplateField HeaderText="Edit" ItemStyle-CssClass="hs1" HeaderStyle-CssClass="header-center">
 
 <ItemTemplate>

    <asp:LinkButton ID="linkEdit" runat="server"    Text="Edit"  OnClick="linkEdit_Click"/>


  </ItemTemplate>
  </asp:TemplateField>


 Add  label  with Database Column 

 <asp:TemplateField HeaderText="Paper ID" ItemStyle-CssClass="hs1" HeaderStyle-CssClass="header-center">
                    <ItemTemplate>

                      <asp:Label ID="LBLID" runat="server" Text='<%# Eval("ID") %>'></asp:Label>

                     
                    </ItemTemplate>
                </asp:TemplateField>



C#   Code  Link button Event



 protected void paybtn_Click(object sender, EventArgs e)
    {

        GridViewRow clickedRow = ((LinkButton)sender).NamingContainer as GridViewRow;
        Label lblID = (Label)clickedRow.FindControl("LBLID");
        lblJ_ID.Text = lblID.Text;
     
         Session["paperid"] = lblJ_ID.Text;
        Response.Redirect("payment1.aspx");       
     

    }









Friday, September 28, 2018

Checkbox List

 protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        int i;
        for (i = 0; i < CheckBoxList1.Items.Count; i++)
        {

            if (CheckBoxList1.SelectedIndex == i)
            {



                TextBox1.Text += CheckBoxList1.Items[i].Text;


            }
            else
            {
         


            }


        }


    }

Break Back Button on browser

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

        function preventBack() { window.history.forward(); }

        setTimeout("preventBack()", 0);

        window.onunload = function () { null };

</script>
</head>

Convert PDF

DOWNLOAD :  itextsharp.dll



using System;
using System.Web;
using System.Web.UI;
using System.Data;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html.simpleparser;



 public override void VerifyRenderingInServerForm(Control control)
    {
        /* Verifies that the control is rendered */
    }
    protected void btnPDF_Click(object sender, EventArgs e)
    {
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=UserDetails.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        this.Page.RenderControl(hw);
        StringReader sr = new StringReader(sw.ToString());
        Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0.0f);
        HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();
        htmlparser.Parse(sr);
        pdfDoc.Close();
        Response.Write(pdfDoc);
        Response.End();
    }

Expiry Limit Coading

 protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text = DateTime.Now.Day.ToString()+"/"+DateTime.Now.Month.ToString()+"/"+DateTime.Now.Year.ToString();
     //   Label2.Text = ;
       // Label3.Text = ;
        if (Label1.Text == "12/2/2012")
        {
            Response.Write("Please renew your account");
        }
        else if (Label1.Text=="13/2/2012")
        {
            Response.Write("Your account is expire");
        }
    }

GRIDVIEW Footer Concept


Set  grideviw  property
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

BackColor="White" BorderColor="#336699" BorderStyle="Solid" BorderWidth="1px"

CellPadding="2" Font-Names="Verdana" ShowFooter="true" Font-Size="10pt"

Width="50%" DataKeyNames="id1" GridLines="Horizontal"

onrowdatabound="GridView1_RowDataBound">

 <Columns>

<asp:BoundField DataField="id1" HeaderText="ino" />

<asp:TemplateField HeaderText="total">

<ItemTemplate>

 <asp:Label ID="lblPrice" runat="server" Text='<%# Eval("total")%>' />

 </ItemTemplate>

 <FooterTemplate>
 <asp:Label ID="lblTotalPrice" runat="server" />
 </FooterTemplate>                 
 </asp:TemplateField>

</Columns>










C# code  :


private void BindData()
{
       
        string cs = @"connection string";
        cn = new SqlConnection(cs);
        cn.Open();

        string k = "select * from invoicetbl";

        SqlDataAdapter da = new SqlDataAdapter(k,cn);

        DataTable table = new DataTable();
      
        da.Fill(table);

        GridView1.DataSource = table;
        GridView1.DataBind();
}

  decimal totalPrice = 0M;
  decimal totalStock = 0M;
  int totalItems = 0;


protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {


        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lblPrice = (Label)e.Row.FindControl("lblPrice");

            Label lblUnitsInStock = (Label)e.Row.FindControl("lblUnitsInStock");

            decimal price = Decimal.Parse(lblPrice.Text);

            totalPrice += price;


            totalItems += 1;
        }

        if (e.Row.RowType == DataControlRowType.Footer)
        {
            Label lblTotalPrice = (Label)e.Row.FindControl("lblTotalPrice");
          

            lblTotalPrice.Text = totalPrice.ToString();         

         
        }
    }

Thursday, September 27, 2018

Create Multiple Popup In AJAX

  <asp:LinkButton ID="lblfake" runat="server" Text=""></asp:LinkButton>

    <cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" PopupControlID="Panel1" TargetControlID="lblfake" BackgroundCssClass="modalBackground" BehaviorID="addAttribute1"></cc1:ModalPopupExtender>
            

<asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" Style="display: none;Width: 600px">


                       // Create Panel 1


                       // create Panel 2



</panel>




         panelupdate.Visible = false;
        panelauthor.Visible = true;

Wednesday, September 26, 2018

Remove Last Character from String in C#, VB.NET with Example

protected void Page_Load(object sender, EventArgs e)
{
string istr = "1,2,3,4,5,6,7,8,9,10,";
string ostr = istr.Remove(istr.Length - 1, 1);
Response.Write(ostr);
}




protected void Page_Load(object sender, EventArgs e)
{
string istr = "1,2,3,4,5,6,7,8,9,10,";
string ostr = istr.Trim(",".ToCharArray());
Response.Write(ostr);
}



protected void Page_Load(object sender, EventArgs e)
{
string istr = "aspdotnet-code.com,";
string ostr = istr.Remove(istr.IndexOf(","));
Response.Write(ostr);
}

Gridview Checkbox

 protected void Button1_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow grow in GridView1.Rows)
        {
            //Searching CheckBox("chkDel") in an individual row of Grid  
            CheckBox chkdel = (CheckBox)grow.FindControl("ch");
            //If CheckBox is checked than delete the record with particular empid  
            if (chkdel.Checked)
            {
                int id = Convert.ToInt32(grow.Cells[0].Text);
                DeleteRecord(id);
            }
        }

Convert Table to Word Document

<div id="divExport" runat="server"> 

      <table >

       //developed format as  your requirement

     </table>


</div>


<button click   event>

{

            Response.AddHeader("content-disposition", "attachment;filename=letter6month.doc");
            Response.Charset = "";
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.ContentType = "application/doc";
            System.IO.StringWriter stringWrite = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
            divExport.RenderControl(htmlWrite);
            Response.Write(stringWrite.ToString());
            Response.End();


}




Sunday, September 23, 2018

Create Live Connection String Under Web.config file

Open web.config File 

<configuration>
  <system.web>


  </system.web>


 <connectionStrings>
    <add name="key" connectionString="Data Source=ip/doamin;
         Network Library=DBMSSOCN;
         Connection Timeout=15;
         Packet Size=4096;
         Integrated Security=no;
         Initial Catalog=databasename;
         User ID=userid;
         password=password;
         Encrypt=no;
         Max Pool Size=50000;" />
  </connectionStrings>

</configuration>


How to Access inside Aspx Page 



using System.Data.SqlClient;
using System.Configuration;


 string cs = ConfigurationManager.ConnectionStrings["keyname"].ToString();
        cn = new SqlConnection(cs);
        cn.Open();





Tuesday, September 18, 2018

How to increase Upload time in File Upload Control

<system.web>


       

  <!--  <httpRuntime maxRequestLength="104857600" executionTimeout="3600" />-->

or



<httpRuntime

executionTimeout="904857600"

maxRequestLength="104857600"

useFullyQualifiedRedirectUrl="false"

minFreeThreads="8"

minLocalRequestFreeThreads="4"

appRequestQueueLimit="100"

enableVersionHeader="true"/>


    
  </system.web>

Sunday, September 16, 2018

Simple virus creatation

Open Notepad and write "start" without quotes


Start
Start
Start


and then save it with .bat extension.


Now double click on this .bat file to run Command Prompt

GRIDVIEW ON ROW DATA BOUND EVENT

 Database Create  Student : roll , name , city , cost  Fix 6 Value  in Database Record  ====================================================...