Thursday, 16 August 2012

"Retrieve a Code behind file method in aspx form Page"

default.aspx


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

<!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">
    <div>
    <U>Showtimes for <%WriteDate();%></U>

    </div>
    </form>
</body>
</html>



default.aspx.cs:

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

public partial class SimpleWebForms : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void WriteDate()
    {
        Response.Write(DateTime.Now.ToString());
    } 
}

"Insert Image into DB and Retrieve into a Data List using asp.net C#"

Create Table in Database:

Column Name        DataType               Key

id                           int                          PK
img                         varchar(500)        

Create Store Procedure:

Insert
create PROC Insert_Image(@img varchar(100))

AS
INSERT INTO Image(img)VALUES(@img)

Retrieve:

create proc sp_Get_Image
as
SELECT img from Image




default.aspx

//Create  Images  Folder in Project

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

<!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">
    <div>
      <table width ="80%" cellpadding="0" cellspacing="0" border ="0" align="center">
            <tr>
                <td>

                    <asp:Label ID="Label1" runat="server" Text="Image"></asp:Label>

                    </td>
                <td>
                    <asp:FileUpload ID="UploadFile" runat="server" />
                    <asp:TextBox ID="txtimg" runat="server"></asp:TextBox>
                    </td>
                
            </tr>            
             <tr>
             <td>
                    <asp:Button ID="btnSave" runat="server" Text="Save" onclick="btnSave_Click" />
                    <asp:Button ID="btnShow" runat="server" Text="Show" onclick="btnShow_Click" />
                </td>
                </tr>
                </table>

                <br />
                <br />
                 <asp:DataList ID="dlImageGet" runat="server" Height="368px" Width="286px">
            <FooterTemplate>
                <table border="1" cellpadding="0" cellspacing="0" width="100%">
                    <tr>
                        <td height="15%" style="background-color: #FF3300">
                        </td>
                    </tr>
                </table>
            </FooterTemplate>
            <HeaderTemplate>
                <table style="width:100%;">
                    <tr>
                        <td style="background-color: #FF0000">
                            </td>
                    </tr>
                    
                </table>
            </HeaderTemplate>
            <ItemTemplate>               
                  <table width="50%" cellpadding ="0" cellspacing="0" border ="0">
                    <tr>
                        <td class="style1">
                            <asp:Image ID="img" runat="server" ImageUrl='<%# Bind("~/Images/{0}","img") %>' />
                            </td>                                              
                    </tr>

                </table>
                </ItemTemplate>
                </asp:DataList>
    </div>
    </form>
</body>
</html>

default.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;

public partial class _Default : System.Web.UI.Page
{

    SqlConnection con = new SqlConnection(@"Data Source=.\sqlexpress;Initial Catalog=DataListDb;Integrated Security=True");
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            Upload_Documents();

            txtimg.Text = "~/Images/" + UploadFile.FileName;
            SqlCommand cmd = new SqlCommand("Insert_Image", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@img", txtimg.Text);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
        }
        catch (Exception ex) { throw new Exception(ex.Message); }
    }


    protected void btnShow_Click(object sender, EventArgs e)
    {
        try
        {
            //SqlCommand cmd = new SqlCommand("Get_Records", sqlcon);

            SqlDataAdapter da = new SqlDataAdapter("sp_Get_Image", con);
            da.SelectCommand.CommandType = CommandType.StoredProcedure;
            DataSet ds = new DataSet();
            da.Fill(ds);
            if (ds.Tables[0].Rows.Count > 0)
            {
                dlImageGet.DataSource = ds.Tables[0];
                dlImageGet.DataBind();
            }
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
    }

    protected void Upload_Documents()
    {
        try
        {
            // Save the file
            string filePath = Server.MapPath("~/Images/" + UploadFile.FileName);
            UploadFile.SaveAs(filePath);

        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
    }
}


Friday, 10 August 2012

"One dropdownlist based upon action of another dropdownlist"

Create Procedure In Database:



create proc sp_BindJobTypeddlCountry
as
select CountryId,CountryName from tblCountry

create proc sp_sp_BindJobTypeddlState
@CountryId int
as
select StateId,StateName from tblState
where CountryId = @CountryId

default.aspx


    <td>
                Country
            </td>
            <td>
                <asp:DropDownList ID="ddlCountry" runat="server" AutoPostBack="true"
                    onselectedindexchanged="ddlCountry_SelectedIndexChanged">
                </asp:DropDownList>
            </td>
        </tr>
        <tr>
            <td>
                State
            </td>
            <td>
                <asp:DropDownList ID="ddlState" runat="server">
                </asp:DropDownList>
            </td>
        </tr>


default.aspx.cs


 //**************** ddl Fill Country *******
    public void MFill_DropCountry()
    {
        try
        {
            DataSet ds = new DataSet();
            SqlCommand cmd = new SqlCommand("sp_BindJobTypeddlCountry", (SqlConnection)Ncconnection.cconnection.MConnection());
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);

            ddlCountry.DataValueField = "CountryId";
            ddlCountry.DataTextField = "CountryName";
            ddlCountry.DataSource = ds.Tables[0];
            ddlCountry.DataBind();

            if (ds.Tables[0].Rows.Count > 0)
            {
                ddlCountry.Items.Insert(0, "----Select----");
               
            }
            else
            {
                ddlCountry.Items.Insert(0, "No Country");
            }
        }
        catch (Exception ex) { throw new Exception(ex.Message); }
    }


    protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
    {
        MFill_DropState(int.Parse(ddlCountry.SelectedValue.ToString()));

    }

    //**************** ddl Fill State *******
    public void MFill_DropState(int ddlCountryId)
    {
        try
        {
            DataSet ds = new DataSet();
            SqlCommand cmd = new SqlCommand("sp_sp_BindJobTypeddlState", (SqlConnection)Ncconnection.cconnection.MConnection());
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@CountryId",ddlCountryId);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);

            ddlState.DataValueField = "StateId";
            ddlState.DataTextField = "StateName";
            ddlState.DataSource = ds.Tables[0];
            ddlState.DataBind();

            if (ds.Tables[0].Rows.Count > 0)
            {
                ddlState.Items.Insert(0, "----Select----");
            }
            else
            {
                ddlState.Items.Insert(0, "No State");
            }
        }
        catch (Exception ex) { throw new Exception(ex.Message); }
    }

Thursday, 9 August 2012

"Encrypt and Decrypt in asp.net for password field and also Login Code"

Procedure1 not Login Code


Cryptography.cs


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using System.Security.Cryptography;
using System.IO;

namespace QueryStringEncryption
{
    public static class Cryptography
    {
        #region Fields

        private static byte[] key = { };
        private static byte[] IV = { 38, 55, 206, 48, 28, 64, 20, 16 };
        private static string stringKey = "!5663a#KN";

        #endregion

        #region Public Methods

        public static string Encrypt(string text)
        {
            try
            {
                key = Encoding.UTF8.GetBytes(stringKey.Substring(0, 8));

                DESCryptoServiceProvider des = new DESCryptoServiceProvider();
                Byte[] byteArray = Encoding.UTF8.GetBytes(text);

                MemoryStream memoryStream = new MemoryStream();
                CryptoStream cryptoStream = new CryptoStream(memoryStream,
                    des.CreateEncryptor(key, IV), CryptoStreamMode.Write);

                cryptoStream.Write(byteArray, 0, byteArray.Length);
                cryptoStream.FlushFinalBlock();

                return Convert.ToBase64String(memoryStream.ToArray());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            return string.Empty;
        }

        public static string Decrypt(string text)
        {
            try
            {
                key = Encoding.UTF8.GetBytes(stringKey.Substring(0, 8));

                DESCryptoServiceProvider des = new DESCryptoServiceProvider();
                Byte[] byteArray = Convert.FromBase64String(text);

                MemoryStream memoryStream = new MemoryStream();
                CryptoStream cryptoStream = new CryptoStream(memoryStream,
                    des.CreateDecryptor(key, IV), CryptoStreamMode.Write);

                cryptoStream.Write(byteArray, 0, byteArray.Length);
                cryptoStream.FlushFinalBlock();

                return Encoding.UTF8.GetString(memoryStream.ToArray());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            //return string.Empty;
        }

        #endregion
    }
}

encryptdecrpt.aspx


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="encryptdecrpt.aspx.cs" Inherits="WebApplication1.encryptdecrpt" %>

<!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">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1"
            runat="server" Text="Button" onclick="Button1_Click" />

            <br />
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
            EnableModelValidation="True" >
            <Columns>
             
                <asp:TemplateField HeaderText="Password">
                    <ItemTemplate>
                        <asp:TextBox ID="txtpass" runat="server"></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>

        </asp:GridView>
    </div>
    </form>
</body>
</html>

encryptdecrpt.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.Text;

namespace WebApplication1
{
    public partial class encryptdecrpt : System.Web.UI.Page
    {
        SqlConnection conn = new SqlConnection(@"Data Source=test;Initial Catalog=Demo;Integrated Security=True");
        DataSet ds = new DataSet();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                mfill();
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            min(QueryStringEncryption.Cryptography.Encrypt(TextBox1.Text));
        }

        private void min(string pass)
    {
        try
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand("Demoinsert", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@password", pass);
            cmd.ExecuteNonQuery();
            conn.Close();
        }
        catch (Exception ex) { throw new Exception(ex.Message); }
    }

        private void mfill()
        {
            SqlCommand cmd = new SqlCommand("select password from D", conn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);       
            GridView1.DataSource = ds.Tables[0];
            GridView1.DataBind();

            ((TextBox)(GridView1.Rows[0].Cells[0].FindControl("txtpass"))).Text = QueryStringEncryption.Cryptography.Decrypt(ds.Tables[0].Rows[0].ItemArray[0].ToString());

        }   
}
}



Procedure2 with Login Code

Login.aspx

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

<!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">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:TextBox ID="TextBox2"
            runat="server"></asp:TextBox><asp:Button ID="Button1" runat="server" 
            Text="Login" onclick="Button1_Click" />
    </div>
    </form>
</body>
</html>


Login.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.Text;

public partial class Login : System.Web.UI.Page
{
    private const string strconneciton = "Data Source=SP2010;Initial Catalog=Demo;Integrated Security=True";
    SqlConnection con = new SqlConnection(strconneciton);

    protected void Page_Load(object sender, EventArgs e)
    {

    }


    private string Encryptdata(string password)
    {
        string strmsg = string.Empty;
        byte[] encode = new
        byte[password.Length];
        encode = Encoding.UTF8.GetBytes(password);
        strmsg = Convert.ToBase64String(encode);
        return strmsg;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            string strpassword = Encryptdata(TextBox2.Text);
            SqlCommand cmd = new SqlCommand("sp_Login", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("Name", TextBox1.Text);
            cmd.Parameters.Add("Password", strpassword);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            if (ds.Tables[0].Rows.Count > 0)
            {

                ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "alert(' Password & UserName Correct '); window.location.href = 'PasswordEncryption.aspx';", true);
                // Response.Redirect("HomeAdmin.aspx");  // throw a Exception
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", @"alert('Invalid Login Email & Password.');", true);
            }
         
        }
        catch (Exception ex) { throw new Exception(ex.Message); }
    }
}





PasswordEncryption.aspx


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

<!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">
    <div>
    <table>
    <tr>
    <td>
    UserName
    </td>
    <td>
    <asp:TextBox ID="txtname" runat="server"></asp:TextBox>
    </td>
    </tr>
     <tr>
    <td>
    Password
    </td>
    <td>
    <asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox>
    </td>
    </tr>
     <tr>
    <td>
    FirstName
    </td>
    <td>
    <asp:TextBox ID="txtfname" runat="server"></asp:TextBox>
    </td>
    </tr>
      <tr>
    <td>
    LastName
    </td>
   
    </tr>
    <tr>
    <td>
    </td>
    <td>
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" 
            onclick="btnSubmit_Click" />
    </td>
    </tr>
    </table>
    </div>
    <div>
    <asp:GridView ID="gvUsers" runat="server" CellPadding="4" ForeColor="#333333" 
            GridLines="None">
        <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
        <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
        <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="White" />
    </asp:GridView>
    </div>
    <div>
    <asp:Button ID="btnDecrypt" runat="server" Text="Decryption" 
            onclick="btnDecrypt_Click" /><br />
    <asp:GridView ID="gvdecryption" runat="server" BackColor="White" AutoGenerateColumns="false"
            BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4" 
            onrowdatabound="gvdecryption_RowDataBound">
        <RowStyle BackColor="White" ForeColor="#330099" />
        <Columns>
            <asp:BoundField DataField="ID" HeaderText="ID" />
            <asp:BoundField DataField="Name" HeaderText="Name" />
            <asp:BoundField DataField="Password" HeaderText="Password" />
            <asp:BoundField DataField="LastName" HeaderText="LastName" />
        </Columns>
        <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
        <PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
        <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
    </asp:GridView>
    </div>
    </form>
</body>
</html>



PasswordEncryption.aspx.cs



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

public partial class PasswordEncryption : System.Web.UI.Page
{

    private const string strconneciton = "Data Source=SP2010;Initial Catalog=Demo;Integrated Security=True";
  SqlConnection con = new SqlConnection(strconneciton);
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindencryptedData();
            BindDecryptedData();
        }
    }
    /// <summary>
    /// btnSubmit event is used to insert user details with password encryption
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string strpassword = Encryptdata(txtPassword.Text);        
        con.Open();
        SqlCommand cmd = new SqlCommand("insert into ED(Name,Password,LastName) values('" + txtname.Text + "','" + strpassword + "','" + txtfname.Text + "')", con);     
        
        cmd.ExecuteNonQuery();
        con.Close();
        BindencryptedData();
        BindDecryptedData();
    }
    /// <summary>
    /// Bind user Details to gridview
    /// </summary>
    protected void BindencryptedData()
    {
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from ED", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        gvUsers.DataSource = ds;
        gvUsers.DataBind();
        con.Close();
    }
    /// <summary>
    /// Bind user Details to gridview
    /// </summary>
    protected void BindDecryptedData()
    {
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from ED", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        gvdecryption.DataSource = ds;
        gvdecryption.DataBind();
        con.Close();
    }
    /// <summary>
    /// Function is used to encrypt the password
    /// </summary>
   
    private string Encryptdata(string password)
    {
        string strmsg = string.Empty;
        byte[] encode = new
        byte[password.Length];
        encode = Encoding.UTF8.GetBytes(password);
        strmsg = Convert.ToBase64String(encode);
        return strmsg;
    }
    private string Decryptdata(string encryptpwd)
    {
        string decryptpwd = string.Empty;

            UTF8Encoding encodepwd = new UTF8Encoding();
            System.Text.Decoder utf8Decode = encodepwd.GetDecoder();
            byte[] todecode_byte = Convert.FromBase64String(encryptpwd);
            int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
            char[] decoded_char = new char[charCount];
            utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
            decryptpwd = new String(decoded_char);
             return decryptpwd;
       
    }
    /// <summary>
    /// rowdatabound condition is used to change the encrypted password format to decryption format
    /// </summary>
   
    protected void gvdecryption_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if(e.Row.RowType==DataControlRowType.DataRow)
        {
           
            string decryptpassword = e.Row.Cells[2].Text;
            e.Row.Cells[2].Text = Decryptdata(decryptpassword);

        }
    }
    /// <summary>
    /// btnDecrypt event is used to bind gridview with decryption of password
    /// </summary>
   
    protected void btnDecrypt_Click(object sender, EventArgs e)
    {
        BindDecryptedData();
    }
}


Wednesday, 8 August 2012

" Select item 'Others' in list which enable textbox for Enter a value "


default.aspx
<asp:ListBox ID="lstFruits" runat="server" AutoPostBack="True" Height="50px"
                    OnSelectedIndexChanged="lstFruit_SelectedIndexChanged" ValidationGroup="g1"
                    Width="195px">
                    <asp:ListItem>---Select---</asp:ListItem>
                    <asp:ListItem>Others</asp:ListItem>
                    <asp:ListItem>Apple</asp:ListItem>
                    <asp:ListItem>Banana</asp:ListItem>
                    <asp:ListItem>Orange</asp:ListItem>
                    <asp:ListItem>Graphes</asp:ListItem>
                </asp:ListBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="lstFruits" ValidationGroup="g1" Width="1px" InitialValue="---Select---">*</asp:RequiredFieldValidator><br />
                <span style="color: #006600; font-size: 12pt;">(If Other Fruits)<br />
                </span>
                <asp:TextBox ID="txt
Fruits
" runat="server" Width="142px" Enabled="False"></asp:TextBox><br />

default.aspx.cs:


protected void lstFruits_SelectedIndexChanged(object sender, EventArgs e)
    {
        if ( lstFruits .SelectedItem.Text  =="Others")
        {
             lstFruits .Enabled = true;
             lstFruits .Focus();
        }
        else
        {
             lstFruits .Enabled = false;
        }
    }


protected void btnInsert_Click(object sender, EventArgs e)
    {
        
       if (lstFruits.SelectedItem.Text == "Others" && 
lstFruits 
.SelectedIndex !=0)

               jobseeker.Fruits = txt
Fruits
.Text.Trim();
           else
               jobseeker.
Fruits
 = lst
Fruits
.SelectedItem.Text.Trim();



}

"Form view and Repeater Control in asp.net"

formviewrepeater.aspx



<asp:FormView ID="FormView1" runat="server" DataKeyNames="AutoID"
        AllowPaging="true" DataSourceID="SqlDataSource1"
        onpageindexchanged="FormView1_PageIndexChanged"
        onitemcommand="FormView1_ItemCommand">

    <ItemTemplate>
   <h2> Page ID : <asp:Label ID="lblpn" runat="server" Text='<%# Eval("AutoID") %>'></asp:Label></h2>
    Page Name: <asp:Label ID="Label1" runat="server" Text='<%# Eval("PageName") %>'></asp:Label> <br / />

    Page Description :<asp:Label ID="Label2" runat="server" Text='<%# Eval("PageDescription") %>'></asp:Label>
    Page Active : <asp:Label ID="Label3" runat="server" Text='<%# Eval("Active") %>'></asp:Label>
        <asp:LinkButton ID="Edit" runat="server" Text="Edit" CommandName="Edit" />
    </ItemTemplate>

    <EditItemTemplate>
   
    <h2> Page ID : <asp:TextBox ID="txlblpn" runat="server" Text='<%# Eval("AutoID") %>' /></h2>
    Page Name: <asp:TextBox ID="txtLabel1" runat="server" Text='<%# Eval("PageName") %>' /> <br / />

    Page Description :<asp:TextBox ID="txtPD" runat="server" Text='<%# Eval("PageDescription") %>' />
        Page Active : <asp:TextBox ID="txtA" runat="server" Text='<%# Eval("Active") %>' />
        <asp:LinkButton ID="lnkUpdate" runat="server" Text="Update" CommandName="Update" />
        <asp:LinkButton ID="lnkCancel" runat="server" Text="Cancel" CommandName="Cancel" />
   
   
    </EditItemTemplate>
       
    </asp:FormView>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:TestConnectionString %>"
   
    SelectCommand="SELECT [AutoID], [PageName], [PageDescription], [Active] FROM [mySampleTable]" >
   
</asp:SqlDataSource>

    <br />
    <br />
    <br />
    <asp:Repeater ID="Repeater1" runat="server"  DataSourceID="SqlDataSource1">
    <ItemTemplate>
   <h2> Page ID : <asp:Label ID="lblpn" runat="server" Text='<%# Eval("AutoID") %>'></asp:Label></h2>
    Page Name: <asp:Label ID="Label1" runat="server" Text='<%# Eval("PageName") %>'></asp:Label> <br / />

    Page Description :<asp:Label ID="Label2" runat="server" Text='<%# Eval("PageDescription") %>'></asp:Label>
    Page Active : <asp:Label ID="Label3" runat="server" Text='<%# Eval("Active") %>'></asp:Label>
        <asp:LinkButton ID="Edit" runat="server" Text="Edit" CommandName="Edit" />
    </ItemTemplate>
    </asp:Repeater>

"List view in asp.net"

listview.aspx:


<asp:ListView ID="ListView1" runat="server">
        <LayoutTemplate>
            <table border="0" cellpadding="1">
                <tr style="background-color: #E5E5FE">
                    <th align="left">
                        <asp:LinkButton ID="lnkId" runat="server">Id</asp:LinkButton>
                    </th>
                    <th align="left">
                        <asp:LinkButton ID="lnkName" runat="server">PageName</asp:LinkButton>
                    </th>
                    <th align="left">
                        <asp:LinkButton ID="lnkType" runat="server">PageDesc</asp:LinkButton>
                    </th>
                    <th>
                        <asp:LinkButton ID="lnkActive" runat="server">Active</asp:LinkButton>
                    </th>
                    <th>
                    </th>
                </tr>
                <tr id="itemPlaceholder" runat="server">
                </tr>
            </table>
            <asp:DataPager ID="ItemDataPager" runat="server" PageSize="5">
                <Fields>
                    <asp:NumericPagerField ButtonCount="2" />
                </Fields>
            </asp:DataPager>
        </LayoutTemplate>
        <ItemTemplate>
            <tr>
                <td>
                    <asp:Label runat="server" ID="lblId"><%#Eval("AutoID")%></asp:Label>
                </td>
                <td>
                    <asp:Label runat="server" ID="lblName"><%#Eval("PageName") %></asp:Label>
                </td>
                <td>
                    <asp:Label runat="server" ID="lblType"><%#Eval("PageDescription")%></asp:Label>
                </td>
                <td>
                    <asp:Label runat="server" ID="lblact"><%#Eval("Active")%></asp:Label>
                </td>
                <td>
                </td>
            </tr>
        </ItemTemplate>
        <AlternatingItemTemplate>
            <tr style="background-color: #EFEFEF">
                <td>
                    <asp:Label runat="server" ID="lblId"><%#Eval("AutoID")%></asp:Label>
                </td>
                <td>
                    <asp:Label runat="server" ID="lblName"><%#Eval("PageName") %></asp:Label>
                </td>
                <td>
                    <asp:Label runat="server" ID="lblType"><%#Eval("PageDescription")%></asp:Label>
                </td>
                <td>
                    <asp:Label runat="server" ID="lblact"><%#Eval("Active")%></asp:Label>
                </td>
                <td>
                </td>
            </tr>
        </AlternatingItemTemplate>
        <InsertItemTemplate>
            <tr id="Tr1" runat="server">
                <td>
                </td>
                <td>
                    <asp:TextBox ID="txtFname" runat="server" Text='<%#Eval("AutoID")%>' Width="100px">First Name</asp:TextBox>
                    <asp:TextBox ID="txtLname" runat="server" Text='<%#Eval("PageName")%>' Width="100px">Last Name</asp:TextBox>
                </td>
                <td>
                    <asp:TextBox ID="txtCtype" runat="server" Text='<%#Eval("PageDescription")%>' Width="100px">Contact Type</asp:TextBox>
                </td>
                <td>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%#Eval("Active")%>' Width="100px">Contact Type</asp:TextBox>
                </td>
                <td>
                    <asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
                </td>
            </tr>
        </InsertItemTemplate>
    </asp:ListView>



listview.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;

public partial class ListView : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack) { MFIll_DetailViewes(); }

    }

    private void MFIll_DetailViewes()
    {
        string strConn = @"Data Source=.\sqlexpress;Initial Catalog=Test;Integrated Security=True";
        SqlConnection conn = new SqlConnection(strConn);
        conn.Open();
        SqlCommand cmd = new SqlCommand("select * from mySampleTable", conn);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);

        ListView1.DataSource = ds.Tables[0];
        ListView1.DataBind();

    }
}