- Visual Studio 2015 (admin: admin)
- Download asp1.zip
- Copy asp1 folder to inetpub/wwwroot as asp2
- Download book.zip
- Copy book.accdb to asp2/app_data
- File / Open Website / asp2
Check for database password
Write code for Button1 in login.aspx:
protectedvoid Button1_Click(object sender, EventArgs e)
{
System.Data.OleDb.OleDbConnection dbconn = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "/App_Data/book.accdb" );
dbconn.Open();
string SqlString = "Select * from Customers where Username='" + TextBox1.Text + "' and Password ='" + TextBox2.Text + "'";
System.Data.OleDb.OleDbCommand dbcommand = new System.Data.OleDb.OleDbCommand(SqlString, dbconn);
object cnt = dbcommand.ExecuteScalar();
if (cnt != null)
{
Session["Fname1"] = TextBox1.Text.ToString();
Response.Redirect("default.aspx");
}
else
{
Label1.Text = "Username or password is wrong";
Label1.Visible = true;
TextBox1.Text = "";
TextBox2.Text = "";
}
}
Data pass between pages – Global variable definition
Global.asax
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
string Fname;
Fname = "";
Session["Fname1"] = Fname;
}
Change default.aspx
- Double click page and write code:
protectedvoid Page_Load(object sender, EventArgs e)
{
Label1.Text = "Welcome, " + Session["Fname1"];
}
Default.aspx
- Add buttons for authors, books, topics, customers, employes, sales, filter, and science books
Prepare authors.aspx
- Add form as new item
- Double click on database
- Click and drag authors table
- Change datagrid properties by clicking on right arrow to change gridview tasks:
- Edit columns (such as header text) Author -> Author Name-Surname
- Enable paging
- Set page size to 5 from Gridview properties
Prepare books.aspx
- Add form as new item
- Double click on database
- Click and drag books table
- A datagrid and a AccessDataSource will be added as default
- Change datagrid properties by clicking on right arrow to change gridview tasks:
- Enable sorting (Delete sort expression for fields that will not be sorted)
Prepare topics.aspx
- Add form as new item
- Double click on database
- Click and drag topics table
- Change datagrid properties by clicking on right arrow to change gridview tasks:
- Enable editing
- Enable deleting
Prepare sales.aspx
- Add form as new item
- Double click on database
- Click and drag sales table
- Change datagrid properties by clicking on right arrow to change gridview tasks:
- Add new column (for calculations)
- Template field (Amount)
- Move column to left
- Add codes to template field and script
asp:TemplateFieldHeaderText="Amount">
ItemTemplate
asp:LabelID="lblTotal"runat="server"Text='<%#Convert.ToDecimal(Eval("Total")) * Convert.ToDecimal(1.08) %>'>
</asp:Label
</ItemTemplate
</asp:TemplateField
scriptrunat="server">
publicstaticdouble GetTotal(double orgtotal)
{
return (orgtotal * 1.08) ;
}
</script
Prepare customers.aspx
- Add form as new item
- Add formview control
- Choose data source as customers table
Prepare employees.aspx
- Add form as new item
- Add datalist control
- Choose data source as employee table
Prepare sciencebooks.aspx
- Create a query for science books
- Add form as new item
- Add gridview
- Choose data source as sciencebooks view
Prepare filter.aspx
- Add form as new item
- Add a dropdownlist
- Choose a new datasource from Authors with author field
- Enable auto postback
- Double click dropdownlist add code for grid data source refresh:
- AccessDataSource1.DataBind();
Add filtering:
- Add gridview control
- Choose data source as authors table
- WHERE / Author = Control / ControlID being dropdownlist1
- Click Add
- Click OK
- Click Finish
Show All:
- Add button
- Change Text value to “Show All”
- Write code for Button_Click as
AccessDataSource2.SelectCommand = "Select * from Authors";
Page_Load
if (IsPostBack)
{TextBox1.Text=””;
TextBox2.Text=””;
}
Week-11; 1