TY-BSCIT                               SUBJECT: Advanced Web Programming
Practical No. 6
A. Aim: Create a web application bind data in a multiline textbox by
     querying in another textbox.
Code:
using   System;
using   System.Collections.Generic;
using   System.Data.SqlClient;
using   System.Linq;
using   System.Web;
using   System.Web.UI;
using   System.Web.UI.WebControls;
namespace p6a
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           protected void Button1_Click(object sender, EventArgs
e)
           {
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "Data Source=JCC-
GIGABYTE;Initial Catalog=TYIT;Integrated Security = True";
            //stringconnStr =
ConfigurationManager.ConnectionStrings["connStr"].ConnectionSt
ring;
            //SqlCommand cmd = new SqlCommand("Select
Id,Name,Password from Login", conn);
            SqlCommand cmd = new SqlCommand(TextBox1.Text,
conn);
            conn.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                TextBox2.Text += reader["ID"].ToString() + " "
+ reader["Name"].ToString() + " "
                + reader["Password"].ToString() + "\n";
            }
SEM-V                                                Roll no.: 711
TY-BSCIT                         SUBJECT: Advanced Web Programming
               reader.Close();
               conn.Close();
           }
    }
}
Output:
SEM-V                                          Roll no.: 711
TY-BSCIT                             SUBJECT: Advanced Web Programming
B. Create a web application to display records by using database.
Code:
protected void Button1_Click(object sender, EventArgs e)
{
    SqlConnection conn = new SqlConnection();
    conn.ConnectionString = "Data Source=JCC-GIGABYTE;Initial
Catalog=tyit;Integrated Security = True";
    //stringconnStr =
ConfigurationManager.ConnectionStrings["connStr"].ConnectionSt
ring;
    //SqlCommand cmd = new SqlCommand("Select * from City",
conn);
    SqlCommand cmd = new SqlCommand(TextBox1.Text, conn);
    conn.Open();
    SqlDataReader reader = cmd.ExecuteReader();
    while (reader.Read())
    {
        //To add new blank line in the text area
        for (int i = 0; i < reader.FieldCount - 1; i++)
        {
            ListBox1.Items.Add(reader[i + 1].ToString());
        }
    }
    reader.Close();
    conn.Close();
}
Output:
SEM-V                                              Roll no.: 711
TY-BSCIT                              SUBJECT: Advanced Web Programming
C. Demonstrate the use of Datalist link control.
CODE:
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="WebForm1.aspx.cs" Inherits="p6c.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:DataList ID="DataList1" runat="server"
DataSourceID="SqlDataSource1">
                <ItemTemplate>
                    CITY:
                    <asp:Label ID="CITYLabel" runat="server"
Text='<%# Eval("CITY") %>' />
                    <br />
<br />
                </ItemTemplate>
            </asp:DataList>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:tyitConnectionString3 %>"
ProviderName="<%$
ConnectionStrings:tyitConnectionString3.ProviderName %>"
SelectCommand="SELECT * FROM [City]"></asp:SqlDataSource>
        </div>
    </form>
</body>
</html>
SEM-V                                               Roll no.: 711
TY-BSCIT   SUBJECT: Advanced Web Programming
SEM-V                    Roll no.: 711
TY-BSCIT   SUBJECT: Advanced Web Programming
OUTPUT:
SEM-V                    Roll no.: 711