DivByZero IndexOutRange and TreeView
DivByZero IndexOutRange and TreeView
Code :
Aspx file
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Exception Demo</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Exception Demo</h1>
<br />
<label>Result: </label>
<asp:Label ID="lblResult" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
C# file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace PracticalTest1
{
public partial class DivZero : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnDivideByZero_Click(object sender, EventArgs e)
{
try
{
// Attempt to divide by zero
int number = int.Parse(txtNumber.Text);
int result = 10 / number; // This may throw DivideByZeroException
- Note : You need to add a sitemap file in your project, using the add >
new items.
After that make 3 more aspx file in the project, named as Default,
Products & ProductsDetail.
Just fill some simple HTML content in these files, like put a H1 and
write some random content.
-Once Done with that fill the below XML content in the sitemap file
created before :
- After that write the below code in your main file other than that
created above!.
Code :
Aspx File
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TreeViewControl.aspx.cs"
Inherits="PracticalTest1.TreeViewControl" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Navigation Demo</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Navigation Demo</h1>
C# File
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace PracticalTest1
{
public partial class TreeViewControl : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// Bind the TreeView and DataList controls to the SiteMapDataSource
TreeView1.DataBind();
DataList1.DataBind();
}
}
}
}