Total Pageviews

7 May 2012

How show value in Grid view in ASP.Net


<%@ Page Title="About Us" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="About.aspx.cs" Inherits="About" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <asp:GridView ID="GridView1" runat="server"
        >
    </asp:GridView>
</asp:Content>
/////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;
public partial class About : System.Web.UI.Page
{
    SqlConnection con;
    SqlCommand cmd;
    string s = ConfigurationManager.ConnectionStrings["conn"].ToString();
    protected void Page_Load(object sender, EventArgs e)
    {
        con = new SqlConnection(s);
       if (!IsPostBack)
        {
            BindGridView();
        }
    }
    public void BindGridView()
    {
        SqlDataAdapter ad = new SqlDataAdapter("select * from Employees order by EmployeeID", con);
        DataSet ds = new DataSet(); ad.Fill(ds);
        GridView1.DataSource = ds; GridView1.DataBind();
    }

   
}

How delete value check box wise in ASP.Net



<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
     

</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
         <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
             AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="CustomerID"
             Width="41px" CellPadding="4" ForeColor="#333333" GridLines="None"
             onselectedindexchanged="GridView1_SelectedIndexChanged" Height="32px">   
        
               <Columns>         
                       <asp:CommandField ShowSelectButton="True" />
                                         <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" InsertVisible="False" ReadOnly="True" /> 
                                                         <asp:BoundField DataField="Firstname" HeaderText="Firstname"  />                 
                                                         <asp:TemplateField HeaderText="Select">
                                                                               <ItemTemplate>   
                                                                                                     
                                                                                                     
                                         <asp:CheckBox ID="chkSelect" runat="server" />    </ItemTemplate>  <HeaderTemplate>
                                        <%--<input id="chkAll" onclick="javascript:SelectAllCheckboxes(this);" runat="server" type="checkbox" />--%>     
                                         
                                                     </HeaderTemplate>         
                                                             </asp:TemplateField>       
                                                                  </Columns>   
                                                                       </asp:GridView>       
<br />
<br />        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Delete" /> 
       <asp:Label ID="lblmsg" runat="server" Text="Label" Visible="false"></asp:Label>
</asp:Content>
////////////////////////////////////////////////
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.Configuration;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ToString()); 
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGridView();
        }
    }
    public void BindGridView()
    {
        SqlDataAdapter ad = new SqlDataAdapter("select * from tbl_CustomerDetail order by CustomerID", con);
        DataSet ds = new DataSet(); ad.Fill(ds);
        GridView1.DataSource = ds; GridView1.DataBind();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in GridView1.Rows)
        {
            CheckBox cb = ((CheckBox)(row.FindControl("chkSelect")));
            if (cb != null && cb.Checked)
            {
                int custID = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);
                string sqlstr = "delete from tbl_CustomerDetail where CustomerID='" + custID + "'"; SqlCommand mycmd;
                mycmd = new SqlCommand(sqlstr, con);
                con.Open();
                mycmd.ExecuteNonQuery();
                BindGridView();
            }
            con.Close();
        }
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
    }
}

How to use Link button in Gridview

About.aspx=>
<%@ Page Title="About Us" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="About.aspx.cs" Inherits="About" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
        <div class="infobox" style="width: 700px; margin: 30px auto">
                <h2>
                    User Profile
                </h2>
                <div class="padding10">
                    <table cellspacing="0" border="0" cellpadding="8" style="width: 90%">
                        <tr>
                            <td align="right" style="width:160px">
                                Username:</td>
                            <td>
                                <asp:Label ID="lblUsername" runat="server"></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">
                                Gender:</td>
                            <td>
                                <asp:Label ID="lblSex" runat="server"></asp:Label></td>
                        </tr>
                        <tr>
                            <td align="right">
                                Age:</td>
                            <td>
                                <asp:Label ID="lblAge" runat="server"></asp:Label></td>
                        </tr>
                        <tr>
                            <td align="right">
                                Location:</td>
                            <td>
                                <asp:Label ID="lblLocation" runat="server"></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">
                                Occupation:</td>
                            <td>
                                <asp:Label ID="lblOccupation" runat="server"></asp:Label></td>
                        </tr>
                        <tr>
                            <td align="right">
                                Interests:</td>
                            <td>
                                <asp:Label ID="lblInterests" runat="server"></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">
                                Joined:</td>
                            <td>
                                <asp:Label ID="lblJoined" runat="server"></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">
                                Last login:</td>
                            <td>
                                <asp:Label ID="lblLastLogin" runat="server"></asp:Label>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
</asp:Content>
About.aspx.cs=>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class About : System.Web.UI.Page
{
    SqlConnection con;
    string s = ConfigurationManager.ConnectionStrings["conn"].ToString();
    protected void Page_Load(object sender, EventArgs e)
    {
        con = new SqlConnection(s);
        SqlDataAdapter ad = new SqlDataAdapter("select * from Employees order by EmployeeID", con);
        string FirstName = "";
   if (this.Request.QueryString["FirstName"] == null)
   {
    return;
   }
            FirstName = Request.QueryString["FirstName"];
   DataSet ds = new DataSet();
            ad.Fill(ds);
   if (ds.Tables[0].Rows.Count == 0)
   {
    return;
   }
   DataRow row = ds.Tables[0].Rows[0];
 
   this.lblUsername.Text = row["FirstName"].ToString();
   this.lblLocation.Text = row["LastName"].ToString();
   this.lblOccupation.Text = row["Address"].ToString();
   this.lblLastLogin.Text = row["City"].ToString();
   this.lblJoined.Text = row["Region"].ToString();
            this.lblAge.Text = row["PostalCode"].ToString();
 
  }
    }

Mouse Event in ASP.Net


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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <a onmouseover="document.getElementById('PopUp').style.display = 'block' " onmouseout="document.getElementById('PopUp').style.display = 'none' " onfocus='this.blur();'><span style="text-decoration: underline;">here</span></a>
       <div id='PopUp' style='display: none; position: absolute; left: 50px; top: 50px; border: solid black 1px; padding: 10px; background-color: rgb(255,255,225); text-align: justify; font-size: 12px; width: 135px;'>
        <asp:CheckBox ID="CheckBox1" runat="server" Text="MCA" /><br /><asp:CheckBox ID="CheckBox2" runat="server" Text="MBA" /><br /><asp:CheckBox
            ID="CheckBox3" runat="server" Text="B-Tech"/>
   
    <br />
    <div style='text-align: center;'><a onmouseover='this.style.cursor="pointer" ' style='font-size: 12px;' onfocus='this.blur();' onclick="document.getElementById('PopUp').style.display ='none' " ><span style="text-decoration: underline;">Close</span></a></div>
       </div>
    </form>
</body>
</html>

How use Login Form on PopUp in ASP.Net



Here in this article we are discuss about popup login form when click on link button and also provide a close button in popup login form.Hope this article is helpfull for You..........



POpupLogin=>

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



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

      

</head>

<body>

    <form id="form1" runat="server">

    <a onmouseover='this.style.cursor="pointer" ' onfocus='this.blur();' onclick="document.getElementById('PopUp').style.display = 'block' " ><span style="text-decoration: underline;">Login Here</span></a>



    <div id='PopUp' style='display: none; position: absolute; left: 50px; top: 50px; border: solid black 1px; padding: 10px; background-color: rgb(255,255,225); text-align: justify; font-size: 12px; width: 300px;'>

       <table><tr><td>UserName</td><td><asp:TextBox ID="tg1" runat="server"></asp:TextBox></td></tr>

    <tr><td>password</td><td><asp:TextBox ID="TextBox1" runat="server" TextMode="Password"></asp:TextBox></td></tr>

    <tr><td></td><td><asp:Button ID="bt" runat="server" Text="Submit" onclick="btn_Click"  /></td></tr>

    </table>

       <br />

       <div style='text-align: right;'><a onmouseover='this.style.cursor="pointer" ' style='font-size: 12px;' onfocus='this.blur();' onclick="document.getElementById('PopUp').style.display = 'none' " ><span style="text-decoration: underline;">Close</span></a></div>

       </div>

    <br />

 







    </form>

</body>

</html>


How use popup on mouse event in ASP.net

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
     <img src="legal1.jpg"
        onmouseover="document.getElementById('PopUp').style.display = 'block' "
        onmouseout="document.getElementById('PopUp').style.display = 'none' "
        onfocus='this.blur();' style="width: 204px; height: 141px"/>
       <div id='PopUp' style='display: none; position: absolute; left: 50px; top: 50px; border: 1px solid black; padding: 10px; background-color: #FF9900; text-align: justify; font-size: 11px; width: 368px;'>
       <h3>Hi</h3>
<p>Amrit Yadav</p>
<p>.NET Programer</p>
<p>In2/1</p>
<p><b>Delhi</b></p>
<h4><a href="http://ambrosia-amrit.blogspot.in/">Visit Here</a></h4>
       </div>
    </form>
</body>
</html>

Contact Form

Name

Email *

Message *