6a . Create a web application to bind data in a multiline textbox by querying in another textbox.

Program:



default.aspx


<%@ 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>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:TextBox ID="TextBox1" runat="server" Height="126px"
            ontextchanged="TextBox1_TextChanged" TextMode="MultiLine"></asp:TextBox>
   
    </div>
    <p>
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="SUBMIT" />
    </p>
    <p>
        <asp:ListBox ID="ListBox1" runat="server"></asp:ListBox>
    </p>
    <p>
        &nbsp;</p>
    </form>
</body>
</html>



     

default.aspx.cs

using System;
using System.Configuration;
using System.Data;
using System.Linq;
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.Xml.Linq;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.SqlTypes;

public partial class _Default : System.Web.UI.Page 
{
    SqlConnection sqlcon =new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\user\Documents\Visual Studio 2008\WebSites\WebSite1\App_Data\Database.mdf;Integrated Security=True;User Instance=True");
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        sqlcon.Open();
        SqlCommand cmd = new SqlCommand(TextBox1.Text, sqlcon);
        SqlDataReader reader = cmd.ExecuteReader();
        ListBox1.Items.Clear();
        while (reader.Read())
        {
            for (int i = 0; i < reader.FieldCount - 1; i++)
            {
                ListBox1.Items.Add(reader[i].ToString());
            }
        }
        reader.Close();
        sqlcon.Close();

    }

Comments