|
|
Sep 09
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication2
{
public enum DateInterval
{
Year,
Month,
Weekday,
Day,
Hour,
Minute,
Second
}
class Program
{
static void Main(string[] args)
{
DateTime dt1 = new DateTime(1994, 12, 12);
DateTime dt2 = new DateTime(1994, 12, 12);
long date = DateDiff(DateInterval.Day, dt1, dt2);
Console.Write(date);
Console.ReadLine();
}
public static long DateDiff(DateInterval interval, DateTime date1, DateTime date2)
{
TimeSpan ts = ts = date2 - date1;
switch (interval)
{
case DateInterval.Year:
return date2.Year - date1.Year;
case DateInterval.Month:
return (date2.Month - date1.Month) + (12 * (date2.Year - date1.Year));
case DateInterval.Weekday:
return Fix(ts.TotalDays) / 7;
case DateInterval.Day:
return Fix(ts.TotalDays);
case DateInterval.Hour:
return Fix(ts.TotalHours);
case DateInterval.Minute:
return Fix(ts.TotalMinutes);
default:
return Fix(ts.TotalSeconds);
}
}
private static long Fix(double Number)
{
if (Number >= 0)
{
return (long)Math.Floor(Number);
}
return (long)Math.Ceiling(Number);
}
}
}
Sep 09
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default13.aspx.cs"
Inherits="Default13" %>
<!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:GridView ID="grd" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="Key" HeaderText="Date" />
<asp:BoundField DataField="Value" HeaderText="Date" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Collections.Generic;
public partial class Default13 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DateTime StartingDate = DateTime.Parse("03/29/2008");
DateTime EndingDate = DateTime.Parse("04/30/2008");
Hashtable ht=new Hashtable();
foreach (DateTime date in GetDateRange(StartingDate, EndingDate))
{
if (date.DayOfWeek.ToString() == "Monday"
|| date.DayOfWeek.ToString()=="Sunday")
{
ht.Add(date.ToShortDateString(),date.DayOfWeek.ToString());
}
}
grd.DataSource=ht;
grd.DataBind();
}
private static List<DateTime> GetDateRange(DateTime StartingDate, DateTime EndingDate)
{
if (StartingDate > EndingDate)
{
return null;
}
List<DateTime> rv = new List<DateTime>();
DateTime tmpDate = StartingDate;
do
{
rv.Add(tmpDate);
tmpDate = tmpDate.AddDays(1);
} while (tmpDate <= EndingDate);
return rv;
}
}
Sep 09
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PagingInRepeater.aspx.cs"
Inherits="PagingInRepeater" %>
<!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="frmTest" method="post" runat="server">
<table width="100%" border="0">
<tr>
<td>
<asp:Label ID="lblCurrentPage" runat="server"></asp:Label></td>
</tr>
<tr>
<td>
<asp:Button ID="cmdPrev" runat="server"
Text=" << " OnClick="cmdPrev_Click"></asp:Button>
<asp:Button ID="cmdNext" runat="server"
Text=" >> " OnClick="cmdNext_Click"></asp:Button></td>
</tr>
</table>
<table border="1">
<asp:Repeater ID="repeaterItems" runat="server">
<ItemTemplate>
<tr>
<td>
<%# DataBinder.Eval(Container.DataItem, "Id") %>
</b></td>
<td>
<%# DataBinder.Eval(Container.DataItem, "FirstName") %>
</b></td>
<td>
<%# DataBinder.Eval(Container.DataItem, "LastName") %>
</b></td>
<td>
<%# DataBinder.Eval(Container.DataItem, "Address") %>
</b></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class PagingInRepeater : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindRepeater();
}
}
public void BindRepeater()
{
if (Session["s"] != null)
{
DataTable dt=new DataTable();
dt=Session["dsTemp"] as DataTable;
PagedDataSource objPds = new PagedDataSource();
objPds.DataSource = dt.DefaultView;
objPds.AllowPaging = true;
objPds.PageSize = 3;
objPds.CurrentPageIndex = CurrentPage;
lblCurrentPage.Text = "Page: " + (CurrentPage + 1).ToString() + " of "
+ objPds.PageCount.ToString();
// Disable Prev or Next buttons if necessary
cmdPrev.Enabled = !objPds.IsFirstPage;
cmdNext.Enabled = !objPds.IsLastPage;
repeaterItems.DataSource = objPds;
repeaterItems.DataBind();
}
else
{
DataTable dt = new DataTable();
dt = GetCustomMadeDataTable();
PagedDataSource objPds = new PagedDataSource();
objPds.DataSource = dt.DefaultView;
objPds.DataSource = dt.DefaultView;
objPds.AllowPaging = true;
objPds.PageSize = 3;
objPds.CurrentPageIndex = CurrentPage;
lblCurrentPage.Text = "Page: " + (CurrentPage + 1).ToString() + " of "
+ objPds.PageCount.ToString();
// Disable Prev or Next buttons if necessary
cmdPrev.Enabled = !objPds.IsFirstPage;
cmdNext.Enabled = !objPds.IsLastPage;
repeaterItems.DataSource = objPds;
repeaterItems.DataBind();
}
}
public DataTable GetCustomMadeDataTable()
{
//Create a new DataTable object
System.Data.DataTable objDataTable = new System.Data.DataTable();
//Create three columns with string as their type
objDataTable.Columns.Add("Id", typeof(string));
objDataTable.Columns.Add("FirstName", typeof(string));
objDataTable.Columns.Add("LastName", typeof(string));
objDataTable.Columns.Add("Address", typeof(string));
objDataTable.Columns.Add("Email", typeof(string));
DataRow dr;
//Adding some data in the rows of this DataTable
for (int i = 0; i <= 50; i++)
{
dr = objDataTable.NewRow();
dr[0] = i.ToString();
dr[1] = "FirstName" + i.ToString();
dr[2] = "LastName" + i.ToString();
dr[3] = "Address" + i.ToString();
dr[4] = "Email" + i.ToString();
objDataTable.Rows.Add(dr);
}
DataColumn[] dcPk = new DataColumn[1];
dcPk[0] = objDataTable.Columns["Id"];
objDataTable.PrimaryKey = dcPk;
Session["dtTemp"] = objDataTable;
return objDataTable;
}
public int CurrentPage
{
get
{
// look for current page in ViewState
object o = this.ViewState["_CurrentPage"];
if (o == null)
return 0; // default to showing the first page
else
return (int)o;
}
set
{
this.ViewState["_CurrentPage"] = value;
}
}
public void cmdPrev_Click(object sender, System.EventArgs e)
{
// Set viewstate variable to the previous page
CurrentPage -= 1;
// Reload control
BindRepeater();
}
public void cmdNext_Click(object sender, System.EventArgs e)
{
// Set viewstate variable to the next page
CurrentPage += 1;
// Reload control
BindRepeater();
}
}
Sep 09
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="InterceptHtml.aspx.cs"
Inherits="InterceptHtml" %>
<!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>
Hello World!
<br />
Hi
</div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.IO;
public partial class InterceptHtml : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Filter = new ReplaceHTML(Response.Filter);
}
/// <summary>
/// Second Method!!!!!!! overide the Render Method.
/// </summary>
/// <param name="writer"></param>
protected override void Render(HtmlTextWriter writer)
{
StringWriter output = new StringWriter();
base.Render(new HtmlTextWriter(output));
writer.Write(output.ToString().Replace("Hi", "This is the replaced text!
Welcome to <a href=\"http://www.aspdotnetcodebook.blogspot.com\
">www.aspdotnetcodebook.blogspot.com</a>"));
}
}
II nd Method
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
/// <summary>
/// To intercept and get a reference to the HTML, we now need to create a
/// class to inherit System.IO.Stream. So, create a new class in
/// </summary>
public class ReplaceHTML : System.IO.Stream
{
private System.IO.Stream Base;
public ReplaceHTML(System.IO.Stream ResponseStream)
{
if (ResponseStream == null)
throw new ArgumentNullException("ResponseStream");
this.Base = ResponseStream;
}
public override int Read(byte[] buffer, int offset, int count)
{
return this.Base.Read(buffer, offset, count);
}
public override void SetLength(long value)
{
}
public override void Write(byte[] buffer, int offset, int count)
{
// Get HTML code
string HTML = System.Text.Encoding.UTF8.GetString(buffer, offset, count);
// Replace the text with something else
HTML = HTML.Replace("Hello World!", "I've replaced the Hello World example!");
// Send output
buffer = System.Text.Encoding.UTF8.GetBytes(HTML);
this.Base.Write(buffer, 0, buffer.Length);
}
public override bool CanRead
{
get { throw new Exception("The method or operation is not implemented."); }
}
public override bool CanSeek
{
get { throw new Exception("The method or operation is not implemented."); }
}
public override bool CanWrite
{
get { throw new Exception("The method or operation is not implemented."); }
}
public override void Flush()
{
HttpContext.Current.Response.Flush();
}
public override long Length
{
get { throw new Exception("The method or operation is not implemented."); }
}
public override long Position
{
get
{
throw new Exception("The method or operation is not implemented.");
}
set
{
throw new Exception("The method or operation is not implemented.");
}
}
public override long Seek(long offset, System.IO.SeekOrigin origin)
{
throw new Exception("The method or operation is not implemented.");
}
}
Sep 09
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PleaseWaitButton.aspx.cs"
Inherits="PleaseWaitButton" %>
<!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>
<div>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class PleaseWaitButton : System.Web.UI.Page
{
protected void Button1_Click(object sender, System.EventArgs e)
{
System.Threading.Thread.Sleep(5000);
ClientScript.RegisterClientScriptBlock(this.GetType(), "reset",
"document.getElementById('" + Button1.ClientID + "').disabled=false;", true);
}
protected void Page_Load(object sender, System.EventArgs e)
{
System.Threading.Thread.Sleep(5000);
Button1.Attributes.Add("onclick", ClientScript.GetPostBackEventReference(Button1, "") + ";
this.value='Please wait...';this.disabled = true;");
}
}
Sep 09
You can create your own configuration section and use one of the staic
methods in the System.Configuration namespace to retrieve the information.
Attached is a simple example. Also lookup configSection element and
IConfigurationSectionHandler interface for additional information.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UserSection.aspx.cs"
Inherits="UserSection" %>
<!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:GridView ID="GridView1" runat="server">
<Columns>
<asp:BoundField DataField="Key" HeaderText="Key" />
<asp:BoundField DataField="Value" HeaderText="Value" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
Code Behind
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class UserSection : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GridView1.DataSource = ConfigExample();
GridView1.DataBind();
}
private static ArrayList ConfigExample()
{
Hashtable htList = new Hashtable();
System.Collections.Specialized.StringDictionary dictionary =
(System.Collections.Specialized.StringDictionary)
System.Configuration.ConfigurationSettings.GetConfig("MySection");
IEnumerator iterator = dictionary.GetEnumerator();
DictionaryEntry entry;
while (iterator.MoveNext())
{
entry = (DictionaryEntry)iterator.Current;
htList.Add(entry.Key);
}
return arList;
}
}
/* IConfigurationSectionHandler Implementation */
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
/// <summary>
/// Summary description for MySectionHander
/// </summary>
namespace MyNamespace
{
public class MySectionHandler :
System.Configuration.IConfigurationSectionHandler
{
#region IConfigurationSectionHandler Members
public object Create(object parent, object configContext, XmlNode
section)
{
System.Collections.Specialized.StringDictionary mySection =
new System.Collections.Specialized.StringDictionary();
if (section == null || section.ChildNodes.Count == 0)
{
return mySection;
}
foreach (XmlNode node in section.ChildNodes)
{
mySection.Add(node.Attributes[0].Value,
node.Attributes[1].Value);
}
return mySection;
}
#endregion
}
}
/* APP.CONFIG OR WEB.CONFIG */
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="MySection" type="MyNamespace.MySectionHandler,
MyAssemblyName"/>
</configSections>
<MySection>
<add key="key1" value="value1" />
<add key="key2" value="value2" />
<add key="key3" value="value3" />
</MySection>
</configuration>
Sep 09
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridViewInsideGridView.aspx.cs"
Inherits="GridViewInsideGridView" %>
<!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:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AutoGenerateSelectButton="True"
DataKeyNames="Id" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="Id" />
<asp:BoundField DataField="Name" />
</Columns>
</asp:GridView>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" Height="50px"
Width="176px">
<Fields>
<asp:BoundField DataField="Id" />
<asp:BoundField DataField="Qul" />
</Fields>
</asp:DetailsView>
</div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class GridViewInsideGridView : System.Web.UI.Page
{
DataSet ds;
protected void Page_Load(object sender, System.EventArgs e)
{
ds = Data();
if (!this.IsPostBack)
{
if (Session["parent"] == null)
{
GridView1.DataSource = ds.Tables["Parent"];
GridView1.DataBind();
}
else
{
GridView1.DataSource = Session["Parent"] as DataTable;
GridView1.DataBind();
}
}
}
private DataSet Data()
{
DataTable dt = new DataTable();
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("Name", typeof(string));
dt.Rows.Add(new object[] { 1, "aaaa" });
dt.Rows.Add(new object[] { 2, "bbbb" });
dt.Rows.Add(new object[] { 3, "cccc" });
dt.TableName = "Parent";
DataTable dtc = new DataTable();
dtc.Columns.Add("Id", typeof(int));
dtc.Columns.Add("Qul", typeof(string));
dtc.Rows.Add(new object[] { 1, "aaaa" });
dtc.Rows.Add(new object[] { 2, "bbbb" });
dtc.Rows.Add(new object[] { 3, "bbbb" });
dtc.TableName = "Child";
DataSet ds = new DataSet();
ds.Tables.Add(dt);
ds.Tables.Add(dtc);
Session["Parent"] = dt;
return ds;
}
protected void GridView1_SelectedIndexChanged(object sender, System.EventArgs e)
{
DataView dv = new DataView(ds.Tables["Child"]);
dv.RowFilter = "Id=" + this.GridView1.SelectedValue.ToString();
DetailsView1.DataSource = dv;
DetailsView1.DataBind();
}
}
Sep 09
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="HideShow.aspx.cs"
Inherits="HideShow" %>
<!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">
<script type="text/javascript">
function ShowHide(obj)
{
if(!obj.checked) {
document.getElementById('tbl_QuestionTags_Software').style.display = 'none';
document.getElementById('tbl_QuestionTags_Software').style.visibility="hidden";
}
else {
document.getElementById('tbl_QuestionTags_Software').style.display = '';
document.getElementById('tbl_QuestionTags_Software').style.visibility ="visible";
}
}
</script>
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBox ID="chk_QuestionTags_Software" runat="server" CssClass="text" Text="Software"
onclick="ShowHide(chk_QuestionTags_Software)" />
<table id="tbl_QuestionTags_Software" border="1" bordercolor="red" cellpadding="0"
cellspacing="0" style="width: 100%">
<tr>
<td>
Test1</td>
<td>
Test1</td>
<td>
Test1</td>
<td>
Test1</td>
<td>
Test1</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Sep 09
let us supposed that you have a textbox is clicked, you need the text that says “Enter your search
here” to dissappear. This is the javascript for this?.
<asp:TextBox ID="TextBox1" runat="server" Text="Search Here"
onkeydown="if (this.value == 'Search Here') this.value = '';"
onclick="this.value=''"></asp:TextBox>
Sep 09
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DataRelation.aspx.cs"
Inherits="DataRelation" %>
<%@ Import Namespace="System.Data" %>
<!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:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="CompanyName"
HeaderText="CompanyName" />
<asp:TemplateField>
<ItemTemplate>
<asp:GridView ID="GridView2"
DataSource='<%#((DataRowView)Container.DataItem).CreateChildView("ParentChild") %>'
runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="Dept"
HeaderText="Department" />
<asp:BoundField DataField="name"
HeaderText="Name" />
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class DataRelation : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridView1.DataSource = CreateDS().Tables["Company"];
GridView1.DataBind();
}
}
private DataSet CreateDS()
{
DataSet ds;
if (Session["DataList_ParentChild"] == null)
{
ds = new DataSet();
DataTable dt = new DataTable("Company");
DataRow dr;
dt.Columns.Add(new DataColumn("ID", typeof(Int32)));
dt.Columns.Add(new DataColumn("CompanyName", typeof(string)));
dt.Columns.Add(new DataColumn("Address", typeof(string)));
dt.Columns.Add(new DataColumn("Name", typeof(string)));
dt.Columns.Add(new DataColumn("Dept", typeof(string)));
for (int i = 1; i < 10; i++)
{
dr = dt.NewRow();
dr[0] = i;
dr[1] = "Company " + i;
dr[2] = "Address " + i;
dr[3] = "Manager name";
dr[4] = "Adminstration";
dt.Rows.Add(dr);
}
ds.Tables.Add(dt);
DataColumn[] Parent_PKColumns = new DataColumn[1];
Parent_PKColumns[0] = dt.Columns["ID"];
dt.PrimaryKey = Parent_PKColumns;
dt = new DataTable("Employees");
dt.Columns.Add(new DataColumn("ID", typeof(Int32)));
dt.Columns.Add(new DataColumn("CompanyID", typeof(Int32)));
dt.Columns.Add(new DataColumn("Name", typeof(string)));
dt.Columns.Add(new DataColumn("Dept", typeof(string)));
for (int i = 1; i < 10; i++)
{
int imax = 0;
if (i % 2 == 0) imax = 5;
else imax = 4;
for (int y = 2; y < imax; y++) //3 emplyees for each company
{
dr = dt.NewRow();
dr[0] = y + i * 5;
dr[1] = i;
dr[2] = "Employee # " + dr[0];
dr[3] = "Dept # " + (y + i);
dt.Rows.Add(dr);
}
}
DataColumn[] Child_PKColumns = new DataColumn[1];
Child_PKColumns[0] = dt.Columns["ID"];
dt.PrimaryKey = Child_PKColumns;
ds.Tables.Add(dt);
DataColumn[] Child_FKColumns = new DataColumn[1];
Child_FKColumns[0] = dt.Columns["CompanyID"];
ds.Relations.Add("ParentChild", Parent_PKColumns, Child_FKColumns);
Session["DataList_ParentChild"] = ds;
}
else
{
ds = (DataSet)Session["DataList_ParentChild"];
}
return ds;
}
}
|