Dear Students of
Virtual University of Pakistan
This is Lecture 01
Online Bus Tick Reservation System.
Watch Video
Design Page Source Code is here
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="addViewStationInfo.aspx.cs" Inherits="OBTRS.admin.addViewStationInfo" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<style type="text/css">
.style1
{
width: 100%;
}
.style2
{
}
.style3
{
color: #000000;
}
.style4
{
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h1>
<span class="style3">Add View Station Info</h1>
<table class="style1">
<tr>
<td class="style2">
Station ID</td>
<td class="style4">
<asp:TextBox ID="TextBox1" runat="server" Enabled="False"></asp:TextBox>
</td>
<td rowspan="5" valign="top">
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ForeColor="Red"
ValidationGroup="1" />
</td>
</tr>
<tr>
<td class="style2">
City Name</td>
<td class="style4">
<asp:TextBox ID="TextBox2" runat="server" Width="250px" ValidationGroup="1"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox2" ErrorMessage="City Name Required"
ForeColor="Red" ValidationGroup="1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style2">
District Name</td>
<td class="style4">
<span class="style3">
<asp:TextBox ID="TextBox3" runat="server" Width="250px" ValidationGroup="1"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="TextBox3" ErrorMessage="District Name Required"
ForeColor="Red" ValidationGroup="1">*</asp:RequiredFieldValidator>
</span>
</td>
</tr>
<tr>
<td class="style2">
Station Name</td>
<td class="style4">
<span class="style3">
<asp:TextBox ID="TextBox4" runat="server" Width="250px" ValidationGroup="1"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="TextBox4" ErrorMessage="Station Name Required"
ForeColor="Red" ValidationGroup="1">*</asp:RequiredFieldValidator>
</span>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td class="style4">
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="SAVE"
Width="100px" ValidationGroup="1" />
</span><asp:Button ID="Button2" runat="server" style="margin-bottom: 0px"
Text="CENCEL" Width="100px" />
</td>
</tr>
<tr>
<td class="style2">
</td>
<td class="style4" colspan="2">
<asp:Label ID="Label1" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td class="style2" colspan="3">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="stationID" DataSourceID="SqlDataSource1"
EmptyDataText="There are no data records to display." BackColor="#CCCCCC"
BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="4"
CellSpacing="2" ForeColor="Black" Width="894px">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="stationID" HeaderText="Station ID" ReadOnly="True"
SortExpression="stationID" />
<asp:BoundField DataField="District" HeaderText="District Name"
SortExpression="District" />
<asp:BoundField DataField="City" HeaderText="City Name" SortExpression="City" />
<asp:BoundField DataField="StationName" HeaderText="Station Name"
SortExpression="StationName" />
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
<RowStyle BackColor="White" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#808080" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#383838" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:myprojectDatabaseConnectionString1 %>"
DeleteCommand="DELETE FROM [stationINFO] WHERE [stationID] = @stationID"
InsertCommand="INSERT INTO [stationINFO] ([City], [District], [StationName]) VALUES (@City, @District, @StationName)"
ProviderName="<%$ ConnectionStrings:myprojectDatabaseConnectionString1.ProviderName %>"
SelectCommand="SELECT [stationID], [City], [District], [StationName] FROM [stationINFO]"
UpdateCommand="UPDATE [stationINFO] SET [City] = @City, [District] = @District, [StationName] = @StationName WHERE [stationID] = @stationID">
<DeleteParameters>
<asp:Parameter Name="stationID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="District" Type="String" />
<asp:Parameter Name="StationName" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="District" Type="String" />
<asp:Parameter Name="StationName" Type="String" />
<asp:Parameter Name="stationID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
</td>
</tr>
</table>
</asp:Content>
C# code of the page is here under
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace OBTRS.admin
{
public partial class addViewStationInfo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
databaseEntities db = new databaseEntities();
//create table object
stationINFO s = new stationINFO();
s.City = TextBox2.Text;
s.District = TextBox3.Text;
s.StationName = TextBox4.Text;
db.stationINFOes.AddObject(s);
db.SaveChanges();
Label1.ForeColor = System.Drawing.Color.Green;
Label1.Text = "New Station has been added";
TextBox1.Text = string.Empty;
TextBox2.Text = string.Empty;
TextBox3.Text = string.Empty;
TextBox4.Text = string.Empty;
GridView1.DataBind();
}
catch (Exception ex)
{
Label1.ForeColor = System.Drawing.Color.Red;
Label1.Text = ex.Message;
}
}
}
}
Any Help Please Email me cs619help@gmail.com
or call 92 301 725 6548