Monday, November 30, 2015

Dynamically populating Grid View

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

public partial class _Default : System.Web.UI.Page
{
    SqlConnection s1;
    protected void Page_Load(object sender, EventArgs e)
    {
        string ss = @"Data Source=VMB-PC\SQLEXPRESS;Initial Catalog=website;Integrated Security=True";
        s1 = new SqlConnection(ss);
        try
        {
            s1.Open();
            DataTable dt = new DataTable();
            dt.Columns.AddRange(new DataColumn[5] { new DataColumn("Rollno", typeof(int)),
                            new DataColumn("Name", typeof(string)),
                            new DataColumn("Department",typeof(string)),
            new DataColumn("Batch",typeof(string)),
            new DataColumn("Section",typeof(string))});
            dt.Rows.Add(1, "h", "a", "s","c");
            GridView1.DataSource = dt;
            GridView1.DataBind();

        }
        catch (Exception excep)
        {
           
        }
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string s = GridView1.SelectedRow.Cells[1].Text;
        Label1.Text = s;

    }
}










<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
    </div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateSelectButton="True" CellPadding="4" ForeColor="#333333" GridLines="None" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
            <AlternatingRowStyle BackColor="White" />
            <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
            <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
            <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
            <SortedAscendingCellStyle BackColor="#FDF5AC" />
            <SortedAscendingHeaderStyle BackColor="#4D0000" />
            <SortedDescendingCellStyle BackColor="#FCF6C0" />
            <SortedDescendingHeaderStyle BackColor="#820000" />
        </asp:GridView>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </form>
    </body>
</html>

Thursday, November 26, 2015

Dynamically populating DropDown List in asp.net C#

string ss = @"Data Source=VMB-PC\SQLEXPRESS;Initial Catalog=website;Integrated Security=True";
        s = new SqlConnection(ss);
     
        s.Open();
        SqlCommand cmd = new SqlCommand("select *from departments",s);
        SqlDataReader d = cmd.ExecuteReader();
        for (int i = 0; d.Read(); i++)
        {

            DropDownList1.Items.Insert(i, d.GetString(0));
        }

Disable BACK button in asp.net c#

  1. <head>
  2. <script type ="text/javascript">  
  3.   
  4.     window.onload = window.history.forward(0);  
  5.     
  6. </script>

  1. </head>

Tuesday, November 24, 2015

Creating Alert In Asp.net C#

protected void but1(object sender, EventArgs e)
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append("<script type = 'text/javascript'>");
        sb.Append("window.onload=function(){");
        sb.Append("alert('");
        sb.Append("Message to be displayed");
        sb.Append("')};");
        sb.Append("</script>");
        ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString());
     
    }

Sunday, August 23, 2015

Dynamic positioning (TEXT GROWING IN HTML) USING JS

<html>
<head>
<script>
var flag=1,fontsize=2;
function start()
{
setInterval("change()",100);
}
function change()
{
h.style.fontSize=fontsize;
h.innerText+=fontsize;
if(fontsize==500)
fontsize=0;

fontsize++;
if(flag==1)
{
document.body.style.backgroundColor="red";
flag=0;
}
else
{
document.body.style.backgroundColor="green";
flag=1;
}
}

</script>
</head>
<body onload="start()">
<p id="h">Hi Welcome</p>

</body>
</html>

Change the background color dynamically using java script

<html>
<head>
<script>

function start()
{
document.body.style.backgroundColor="red";
}

</script>
</head>
<body>
<p>Hi Welcome</p>
<input type="button" onclick="start()" value="Click me" >
</body>
</html>

Collections CHILDREN in html using JS

Collections: 
It is an array of all the elements(tags) that are present in the html page.

documemt.all==> Is a collection/array of all the elements in the html page in the order in which they appear on the html page..

documemt.all.length==>Is used to find out howmany elements/tags are there in the html page.

document.all[index].children==>Is an array/collection of all the immediate child-elements of the all[index] element.

document.all[index].children.length==>Is used to find out howmany elements/tags are there inside the all[index] element/tags.

<html>
<head>
<script>
var data=" THE TAGS ARE:";
function start()
{
for(var i=0;i<document.all.length;i++)
{
data+=" <br><br> TAG: "+document.all[i].tagName;
if(document.all[i].children.length>0)
data+="   <b> ITS CHILD : </b>";
for(var j=0;j<document.all[i].children.length;j++)
data+=" "+document.all[i].children[j].tagName;
}

para.innerHTML+=data;
}

</script>
</head>
<body>
<p id="para">Hi Welcome</p>
<input type="button" onclick="start()" value="Click me" >
</body>
</html>