You are on page 1of 24

// SQL Select Command

SqlCommand mySqlSelect = new SqlCommand("select * from categories",


mySQLconnection);
mySqlSelect.CommandType = CommandType.Text;
SqlDataAdapter mySqlAdapter = new SqlDataAdapter(mySqlSelect);
DataSet myDataSet = new DataSet();
mySqlAdapter.Fill(myDataSet);

// Convert DataSet to DataView using DefaultView property associated with


DataTable stored inside the DataSet
DataView dView = myDataSet.Tables[0].DefaultView;
You can bind the initialized object of DataView class with ASP.Net data
presentation control such as GridVew, DataList or repeater to display the
data on ASP.Net web page.
E.g.:
GridView1.DataSource = dView;
GridView1.DataBind();

[code:c#]
// SQL Select Command
SqlCommand mySqlSelect = new SqlCommand("select * from categories",
mySQLconnection);
mySqlSelect.CommandType = CommandType.Text;
SqlDataAdapter mySqlAdapter = new SqlDataAdapter(mySqlSelect);
DataSet myDataSet = new DataSet();
mySqlAdapter.Fill(myDataSet);
// Convert DataSet to DataTable by getting DataTable at first zero-based index of
DataTableCollection
DataTable myDataTable = myDataSet.Tables[0];
[/code]
Above C# code shows how to fill the DataSet with data retrieved from the SQL
Database and convert it into a single DataTable. Next step is to display the data stored
in DataTable. You can bind the Data Table directly to the ASP.Net Data presentation
controls such as GridView, DataList or repeater to display the data. Or you can read the
data stored in each DataRow using the C# foreach loop as following:

[code:c#]
// foreach loop to get each DataRow of DataTable retrieved from DataSet
foreach (DataRow dRow in myDataTable.Rows)
{
Response.Write(dRow[ "categoryId" ].ToString() + " " + dRow[ "categoryName"
].ToString() + "<br/>");
}
[/code
p 2008

In ASP.Net, to convert DataSet to ArrayList using C# code requires some


knowledge about DataSet: in-memory data collection. You must know that ASP.Net
DataSet can hold the schema, DataTable as well as data retrieved from the SQL
database table. DataSet represents the in-memory structure of table data retrieved
from the database. DataSet as the name suggests consists of DataTable collection that
can store the table structure i.e. column names, table name. It stores
eachDataTable in the collection at zero- based index that can be retrieved by passing
the index of table whose data you want to manipulate, display and bind to any data
presentation control of ASP.Net. For converting the ASP.Net DataSet to ArrayListyou
can select the DataTable based on its index in the DataTable Collection and insert its
each row into the ArrayList as an object.

C# code for ASP.Net Convert DataSet to ArrayList


[code:c#]
// SQL Select Command
SqlCommand mySqlSelect = new SqlCommand("select * from categories",
mySQLconnection);
mySqlSelect.CommandType = CommandType.Text;
SqlDataAdapter mySqlAdapter = new SqlDataAdapter(mySqlSelect);
DataSet myDataSet = new DataSet();
mySqlAdapter.Fill(myDataSet);
// create an instance for ArrayList
ArrayList myArrayList = new ArrayList();
// foreach loop to read each DataRow of DataTable stored inside the DataSet
foreach (DataRow dRow in myDataSet.Tables[0].Rows)
{
// add DataRow object to ArrayList
myArrayList.Add(dRow);
}
[/code]
Above C# code shows how to convert DataSet to ArrayList. Add function of ArrayList
accepts the parameter as object type. DataRow object has been passed in the above
example to the Add function of ArrayList to store it in the collection.

Now the next step is also necessary to retrieve the values of columns stored in each
row added to the ArrayList collection. Following C# code shows how to retrieve the
ArrayList item as object, then convert it to DataRow and read the column value to
display it on the ASP.Net web page:
[code:c#]
// foreach loop to get each item of ArrayList
foreach (Object objRow in myArrayList)
{
Response.Write(((DataRow)objRow)[ "categoryId" ].ToString() + " " +
((DataRow)objRow)[ "categoryName" ].ToString() + "<br/>");
}
[/code]

C# Code for ASP.Net DataTable DefaultView RowFilter


[code:c#]
// Initialize a DataTable
DataTable myDataTable = new DataTable();
// Initialize DataColumn
DataColumn myDataColumn = new DataColumn();
// Add First DataColumn
// AllowDBNull property
myDataColumn.AllowDBNull = false;
// set AutoIncrement property to true
myDataColumn.AutoIncrement = true;
// set AutoIncrementSeed property equal to 1
myDataColumn.AutoIncrementSeed = 1;
// set AutoIncrementStep property equal to 1
myDataColumn.AutoIncrementStep = 1;
// set ColumnName property to specify the column name
myDataColumn.ColumnName = "auto_ID";
// set DataType property of the column as Integer
myDataColumn.DataType = System.Type.GetType( "System.Int32" );
// set Unique property of DataColumn to true to allow unqiue value for this column in
each row
myDataColumn.Unique = true;
// Add and Create a first DataColumn
myDataTable.Columns.Add(myDataColumn);

// Add second DataColumn


// initialize a new instance of DataColumn to add another column with different
properties.
myDataColumn = new DataColumn();
myDataColumn.ColumnName = "Unit_Name";
// set DataType property of the column as String
myDataColumn.DataType = System.Type.GetType( "System.String" );
// Add and Create a Second DataColumn
myDataTable.Columns.Add(myDataColumn);
// Add third DataColumn
// initialize a new instance of DataColumn to add another column with different
properties.
myDataColumn = new DataColumn();
myDataColumn.ColumnName = "Unit_Price";
// set DataType property of the column as Double
myDataColumn.DataType = System.Type.GetType( "System.Double" );
// Add and Create a Third DataColumn
myDataTable.Columns.Add(myDataColumn);
// Add fourth DataColumn
// initialize a new instance of DataColumn to add another column with different
properties.
myDataColumn = new DataColumn();
myDataColumn.ColumnName = "Units_In_Pack";
// set DataType property of the column as Integer
myDataColumn.DataType = System.Type.GetType( "System.Int32" );
// Add and Create a fourth DataColumn
myDataTable.Columns.Add(myDataColumn);
// Add fifth DataColumn
// initialize a new instance of DataColumn to add another column with different
properties.
myDataColumn = new DataColumn("Net_Price", System.Type.GetType(
"System.Double" ), "Units_In_Pack * Unit_Price");
// Add and Create a fifth DataColumn
myDataTable.Columns.Add(myDataColumn);
// create a new row using NewRow() function of DataTable.
// dataRow object will inherit the schema of myDataTable to create a new row
DataRow dataRow = myDataTable.NewRow();
dataRow["Unit_Name"] = "ASP.Net 2.0 [3 in 1 Pack]";
dataRow["Unit_Price"] = "35.19";

dataRow["Units_In_Pack"] = "3";
// add new data row to the data table.
myDataTable.Rows.Add(dataRow);
// similarly adds the second row to the DataTable
dataRow = myDataTable.NewRow();
dataRow["Unit_Name"] = "ASP.Net 2.0 with AJAX [4 in 1 Pack]";
dataRow["Unit_Price"] = "39.39";
dataRow["Units_In_Pack"] = "4";
myDataTable.Rows.Add(dataRow);
// similarly adds the third row to the DataTable
dataRow = myDataTable.NewRow();
dataRow["Unit_Name"] = "ASP.Net 3.5 with AJAX [4 in 1 Pack]";
dataRow["Unit_Price"] = "42.19";
dataRow["Units_In_Pack"] = "4";
myDataTable.Rows.Add(dataRow);
myDataTable.AcceptChanges();
GridView1.DataSource = myDataTable;
GridView1.DataBind();
[/code]
Above C# code shows how to create a DataTable and bind it to GridView to display the
data stored in it. To filter the Rows you use the following C# code line before the
"GridView1.DataSource = myDataTable":
myDataTable.DefaultView.RowFilter = "unit_price < 40";

Above filter expression will generate the customized view within the myDataTable
object of DataTable. RowFilter property accepts the string value similar to the where
clause of SQL select query. For example: "columnName = 10", "columnName <= 10",
"columnName >= 10" or "columnName <> 10" for integer values, and "columnName =
Tim" for string values.
myDataTable.DefaultView.RowFilter = "unit_price < 40";

myDataTable.DefaultView.Sort = "unit_price desc";

GridView1.DataSource = myDataTable;
GridView1.DataBind();

You can use both properties of DefaultView property of DataTable to sort the filtered
rows. Or you can use one of them to Sort all the rows present in the DataTable. Above
code will generate the following output:

DataRow[] filterRows = myDataTable.Select("Unit_Price < 40", "unit_price


desc");

Above C# code shows the use of sort parameter with string value to filter the rows of
DataTable based on search filterExpression. You can match the output here:

SqlConnection con = new SqlConnection("Server=You server name or comp


name;Database=Yourdatabasename;Trusted_Connectopn=True");
SqlCommand cmd = new SqlCommand("Write your sql query here eg. select * from Table name");
con.Open();
DataSet ds = new DataSet(cmd,con);
SqlDataAdapter da = new SqlDataAdapter();
da.Fill(ds);
con.Close();
Using System.Data;
Using System.Data.SqlClient;

SqlConnection con = null;


SqlCommand cmd = null;
SqlDataReader rdr ;
try
{
con = new SqlConnection("Data Source = Server Name; Initial Catalog = Database Name; User Name
= user name; password = password");
con.Open();
cmd = new SqlCommand(con,"sql query");
rdr = cmd.ExecuteReader();

while(rdr.Read())
{
// Operate on fetched data
}
}
catch(Exception exp)
{
MessageBox(exp.Message);
}
finally
{
if(cmd != null)
cmd.Close();
if(con != null)
con.Close();
if(rdr != null)
rdr.Dispose();
}

public static void ReadData(string connectionString, string queryString)


{
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
OleDbCommand command = new OleDbCommand(queryString, connection);
connection.Open();
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(reader[0].ToString());
}
reader.Close();
}
}
private static void ReadOrderData(string connectionString)
{
string queryString =
"SELECT OrderID, CustomerID FROM dbo.Orders;";
using (SqlConnection connection = new SqlConnection(
connectionString))
{
SqlCommand command = new SqlCommand(
queryString, connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
try
{
while (reader.Read())

{
Console.WriteLine(String.Format("{0}, {1}",
reader[0], reader[1]));
}
}
finally
{
// Always call Close when done reading.
reader.Close();
}
}
}

public class MyDetails


{
private int age;
public int Age
{
get { return age; }
set { age = value; }
}
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
private int id;
public int Id
{
get { return id; }
set { id = value; }
}
}
ArrayList sequence = new ArrayList();
SqlConnection sqlCon = null;
try
{
sqlCon = new SqlConnection();
sqlCon.ConnectionString = "Your Connection String";
SqlCommand cmd = new SqlCommand();
cmd.Connection = sqlCon;
cmd.CommandText = "SELECT * FROM StudentInfo";
sqlCon.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
MyDetails m = new MyDetails();

m.Id = (int)reader[0];
m.Name = reader[1].ToString();
m.Age = (int)reader[2];
sequence.Add(m);
}
dataGridView1.DataSource = sequence;
}
finally
{
sqlCon.Close();
}

private static void Main(string[] args)


{
using (Bitmap bitmap1 = new Bitmap(100, 100))
{
Console.WriteLine("Width: {0}, Height: {1}", bitmap1.Width,
bitmap1.Height);
}
Console.ReadLine();
}

The using keyword is well known to C# developers. Its main purpose,


the using directive, is to create a shortcut to namespaces used in the code, but it's not the
only purpose. using can also be used to access an object in a bounded scope if this object's
type implements the IDisposable interface, which means it contains a public
Dispose() method
static void Main(string[] args)
{
using (MyClass myClazz = new MyClass())
{
myClazz.DoSomething();
}
}

Inside the using statement, we can use myClazz as a regular instance of MyClass in
this case, call its publicmethod. Outside the using statement, myClazz doesn't exist.
What happens behind the scenes? Actually, it's very simple. The C# compiler will translate
the above usingstatement at compile time into something like this:

Collapse | Copy Code


static void Main(string[] args)
{
{
MyClass myClazz = new MyClass();
try
{
myClazz.DoSomething();
}
finally
{
IDisposable dis = myClazz as IDisposable;
if (dis != null)
{
dis.Dispose();
}
}
}
}

The foreach statement repeats a group of embedded statements for each element in an array or an
object collection. The foreach statement is used to iterate through the collection to get the desired
information, but should not be used to change the contents of the collection to avoid unpredictable side
effects.

Remarks
The embedded statements continue to execute for each element in the array or collection. After the
iteration has been completed for all the elements in the collection, control is transferred to the next
statement following the foreach block.
At any point within the foreach block, you can break out of the loop using the break keyword, or step
directly to the next iteration in the loop by using the continue keyword.
A foreach loop can also be exited by the goto, return, or throwstatements.
For more information on the foreach keyword and code samples, see the following topics:
Using foreach with Arrays (C# Programming Guide)
How to: Access a Collection Class with foreach (C# Programming Guide)

Example
In this example, foreach is used to display the contents of an array of integers.
// cs_foreach.cs

class ForEachTest
{
static void Main(string[] args)
{
int[] fibarray = new int[] { 0, 1, 2, 3, 5, 8, 13 };
foreach (int i in fibarray)
{
System.Console.WriteLine(i);
}
}
}
Output

0
1
2
3
5
8
13

public abstract class AbstractFactory


{
public abstract AbstractProductA CreateProductA();
public abstract AbstractProductB CreateProductB();
}
// Concrete Factory #1
public class ConcreteFactory1: AbstractFactory
{
public override AbstractProductA CreateProductA()
{
return new ProductA1();
}
public override AbstractProdictB CreateProductB()
{
return new ProductB1();
}
}
// Concrete Factory #2
public class ConcreteFactory2: AbstractFactory
{
public override AbstractProductA CreateProductA()
{
return new ProductA2();
}
public override AbstractProductB CreateProductB()
{
return new ProductB2();

}
}
// Abstract product A
public abstract class AbstractProductA
{
public abstract void MethodA();
}
// Abstract product B
public abstract class AbstractProductB
{
public abstract void MethodB();
}
// Product A1
public class ProductA1: AbstractProductA
{
public override void MethodA()
{
Console.WriteLine("ProductA1.MethodA() Called");
}
}
// Product A2
public class ProductA2: AbstractProductA
{
public override void MethodA()
{
Console.WriteLine("ProductA2.MethodA() Called");
}
}
// Product B1
public class ProductB1: AbstractProductB
{
public override void MethodB()
{
Console.WriteLine("ProductB1.MethodB() Called");
}
}
// Product B2
public class ProductB2: AbstractProductB
{
public override void MethodB()
{
Console.WriteLine("ProductB2.MethodB() Called");
}
}
// Client class, consumer of products and
// user of Abstract Factory
public class Client
{
public static void Main()
{
AbstractFactory factory;
AbstractProductA prodA;
AbstractProductB prodB;
// Create instances of products from factory A

factory = new ConcreteFactoryA();


prodA = factory.CreateProductA();
prodB = factory.CreateProductB();
prodA.MethodA();
prodB.MethodB();
// Create instances of products from factory B
factory = new ConcreteFactoryB();
prodA = factory.CreateProductA();
prodB = factory.CreateProductB();
prodA.MethodA();
prodB.MethodB();
}
}

<script type="text/JavaScript">
alert('hello world');
</script>

You can use the ASP.NET codebehind to write it to the page


ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + myStringVariable + "');", true);
Collapse | Copy Code
private void Page_Load( object sender, System.EventArgs e )
{
MessageBox.Show( "Hello World!" );
MessageBox.Show( "This is my second message." );
MessageBox.Show( "Alerts couldnt be simpler." );
}

As you can see from the example above, the developer isn't restricted to displaying one
message box.

Behind the scenes


The first time the Show method is invoked from a Page, a System.Collections.Queue is
created and stored in a private static HashTable. The Queue is used to hold all of the
message's associated with current executing Page. We also "wire up"
the Page.UnLoad event so we can write the client side JavaScript to the response stream
after the Page has finished rendering its HTML.
The reason we store the Queue in a Hashtable is because we are using static methods.
There is the potential for multiple pages to be using the class at the same time (on separate
threads). Therefore we need to make sure we know which messages belong to which page.

To accomplish this we simply use the Page's reference as the key in theHashTable. We
obtain a reference to the current executing page by casting the
current IHttpHandler toSystem.Web.UI.Page. The current IHttpHandler can be
obtained from HttpContext.Current.Handler. In most cases this will be a class either
directly or indirectly derived from System.Web.UI.Page.

Source Code
Collapse | Copy Code
public class MessageBox
{
private static Hashtable m_executingPages = new Hashtable();
private MessageBox(){}
public static void Show( string sMessage )
{
// If this is the first time a page has called this method then
if( !m_executingPages.Contains( HttpContext.Current.Handler ) )
{
// Attempt to cast HttpHandler as a Page.
Page executingPage = HttpContext.Current.Handler as Page;
if( executingPage != null )
{
// Create a Queue to hold one or more messages.
Queue messageQueue = new Queue();
// Add our message to the Queue
messageQueue.Enqueue( sMessage );
// Add our message queue to the hash table. Use our page reference
// (IHttpHandler) as the key.
m_executingPages.Add( HttpContext.Current.Handler, messageQueue );
// Wire up Unload event so that we can inject
// some JavaScript for the alerts.
executingPage.Unload += new EventHandler( ExecutingPage_Unload );
}
}
else
{
// If were here then the method has allready been
// called from the executing Page.
// We have allready created a message queue and stored a
// reference to it in our hastable.
Queue queue = (Queue) m_executingPages[ HttpContext.Current.Handler ];
// Add our message to the Queue
queue.Enqueue( sMessage );
}
}
// Our page has finished rendering so lets output the
// JavaScript to produce the alert's
private static void ExecutingPage_Unload(object sender, EventArgs e)
{
// Get our message queue from the hashtable
Queue queue = (Queue) m_executingPages[ HttpContext.Current.Handler ];

if( queue != null )


{
StringBuilder sb = new StringBuilder();
// How many messages have been registered?
int iMsgCount = queue.Count;
// Use StringBuilder to build up our client slide JavaScript.
sb.Append( "<script language="'javascript'">" );
// Loop round registered messages
string sMsg;
while( iMsgCount-- > 0 )
{
sMsg = (string) queue.Dequeue();
sMsg = sMsg.Replace( "\n", "\\n" );
sMsg = sMsg.Replace( "\"", "'" );
sb.Append( @"alert( """ + sMsg + @""" );" );
}
// Close our JS
sb.Append( @"</script>" );
// Were done, so remove our page reference from the hashtable
m_executingPages.Remove( HttpContext.Current.Handler );
// Write the JavaScript to the end of the response stream.
HttpContext.Current.Response.Write( sb.ToString() );
}
}
}

<style type="text/css">

/*Example CSS for the two demo scrollers*/

#pscroller1{
width: 200px;
height: 100px;
border: 1px solid black;
padding: 5px;
background-color: lightyellow;
}

#pscroller2{
width: 350px;
height: 20px;
border: 1px solid black;
padding: 3px;
}

#pscroller2 a{
text-decoration: none;
}

.someclass{ //class to apply to your scroller(s) if desired


}

</style>

<script type="text/javascript">

/*Example message arrays for the two demo scrollers*/

var pausecontent=new Array()


pausecontent[0]='<a href="http://www.javascriptkit.com">JavaScript Kit</a><br />Comprehensive
JavaScript tutorials and over 400+ free scripts!'
pausecontent[1]='<a href="http://www.codingforums.com">Coding Forums</a><br />Web coding and
development forums.'

pausecontent[2]='<a href="http://www.cssdrive.com" target="_new">CSS Drive</a><br />Categorized


CSS gallery and examples.'

var pausecontent2=new Array()


pausecontent2[0]='<a href="http://www.news.com">News.com: Technology and business reports</a>'
pausecontent2[1]='<a href="http://www.cnn.com">CNN: Headline and breaking news 24/7</a>'
pausecontent2[2]='<a href="http://news.bbc.co.uk">BBC News: UK and international news</a>'

</script>

<script type="text/javascript">

/***********************************************
* Pausing up-down scroller- Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

function pausescroller(content, divId, divClass, delay){


this.content=content //message array content
this.tickerid=divId //ID of ticker div to display information
this.delay=delay //Delay between msg change, in miliseconds.
this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
this.hiddendivpointer=1 //index of message array for hidden div
document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div
class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div

class="innerDiv" style="position: absolute; width: 100%; visibility: hidden"


id="'+divId+'2">'+content[1]+'</div></div>')
var scrollerinstance=this
if (window.addEventListener) //run onload in DOM2 browsers
window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
else if (window.attachEvent) //run onload in IE5.5+
window.attachEvent("onload", function(){scrollerinstance.initialize()})
else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
setTimeout(function(){scrollerinstance.initialize()}, 500)
}

// ------------------------------------------------------------------// initialize()- Initialize scroller method.


// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

pausescroller.prototype.initialize=function(){
this.tickerdiv=document.getElementById(this.tickerid)
this.visiblediv=document.getElementById(this.tickerid+"1")
this.hiddendiv=document.getElementById(this.tickerid+"2")
this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth(this.visibledivtop*2)+"px"
this.getinline(this.visiblediv, this.hiddendiv)
this.hiddendiv.style.visibility="visible"

var scrollerinstance=this
document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
if (window.attachEvent) //Clean up loose references in IE
window.attachEvent("onunload",
function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}

// ------------------------------------------------------------------// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

pausescroller.prototype.animateup=function(){
var scrollerinstance=this
if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){
this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px"
this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px"
setTimeout(function(){scrollerinstance.animateup()}, 50)
}
else{
this.getinline(this.hiddendiv, this.visiblediv)
this.swapdivs()
setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
}

// ------------------------------------------------------------------// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

pausescroller.prototype.swapdivs=function(){
var tempcontainer=this.visiblediv
this.visiblediv=this.hiddendiv
this.hiddendiv=tempcontainer
}

pausescroller.prototype.getinline=function(div1, div2){
div1.style.top=this.visibledivtop+"px"
div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
}

// ------------------------------------------------------------------// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage=function(){
var scrollerinstance=this
if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
setTimeout(function(){scrollerinstance.setmessage()}, 100)

else{
var i=this.hiddendivpointer
var ceiling=this.content.length
this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
this.animateup()
}
}

pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any


if (tickerobj.currentStyle)
return tickerobj.currentStyle["paddingTop"]
else if (window.getComputedStyle) //if DOM2
return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
else
return 0
}

</script>
<script type="text/javascript">

//new pausescroller(name_of_message_array, CSS_ID, CSS_classname, pause_in_miliseconds)

new pausescroller(pausecontent, "pscroller1", "someclass", 3000)


document.write("<br />")

new pausescroller(pausecontent2, "pscroller2", "someclass", 2000)

</script>
<asp:ScriptManager id="Scrptmanagr" runat="server"></asp:ScriptManager>
<asp:UpdatePanel id="updtpanl" runat="server">
<ContentTemplate>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:testConnectionString %>"
SelectCommand="SELECT [arrange_by_id], [arrange_by] FROM [arrange_by]">
</asp:SqlDataSource>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<asp:HyperLink ID="HyperLink3" NavigateUrl='<%#
string.Format("{0}?SortingType={1}",Request.AppRelativeCurrentExecutionFilePath,
Eval("arrange_by_id"))%>' runat="server"><%# Eval("arrange_by")
%></asp:HyperLink>
</ItemTemplate>
<SeparatorTemplate>
|
</SeparatorTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$
ConnectionStrings:testConnectionString %>"
SelectCommand="SELECT [alphabet_id],[arrange_by_id], [value] FROM [alphabet] WHERE
([arrange_by_id] = @arrange_by_id)">
<SelectParameters>
<asp:QueryStringParameter Name="arrange_by_id" QueryStringField="SortingType"
Type="Int32" DefaultValue="1" />
</SelectParameters>
</asp:SqlDataSource>
<br /><br />
<asp:Repeater ID="Repeater2" runat="server" DataSourceID="SqlDataSource2">
<ItemTemplate>
<asp:HyperLink ID="hyper1" runat="server"
NavigateUrl='<%#string.Format("{0}?SortingType={1}&SortBy={2}",Request.AppRelative
CurrentExecutionFilePath, Eval("arrange_by_id"),Eval("value"))%>'><%#
Eval("value")%></asp:HyperLink>
</ItemTemplate>
<SeparatorTemplate>
|
</SeparatorTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>

<asp:Repeater ID="MySponsoredChildrenList" runat="server"


OnItemDataBound="MySponsoredChildrenList_ItemDataBound"
OnItemCommand="MySponsoredChildrenList_ItemCommand">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<br />
<div id="OuterDiv">
<div id="InnerLeft">
<asp:Image ID="ProfilePic" runat="server"
ImageUrl='<%#"~/Resources/Children Images/" + String.Format("{0}",
Eval("Primary_Image")) %>'
Width='300px' Style="max-height: 500px" /></div>
<div id="InnerRight">
<asp:HiddenField ID="ChildID" runat="server" Value='<%#
DataBinder.Eval(Container.DataItem, "Child_ID") %>'/>
<span style="font-size: 20px; font-weight:bold;"><%#
DataBinder.Eval(Container.DataItem, "Name") %>
<%# DataBinder.Eval(Container.DataItem, "Surname") %></span>
<br /><br /><br />
What have you been up to?
<br /><br />
<span style="font-style:italic">"<%#
DataBinder.Eval(Container.DataItem, "MostRecentUpdate")%>"</span>
<span style="font-weight:bold"> -<%#
DataBinder.Eval(Container.DataItem, "Update_Date", "{0:dd/MM/yyyy}")%></span><br
/><br /><br />Sponsored till:
<%# DataBinder.Eval(Container.DataItem, "End_Date",
"{0:dd/MM/yyyy}")%>
<br /><br />
<asp:Button ID="ChildProfileButton" runat="server" Text="View
CommandName="ViewProfile" />
</div>
</div>
<br />
</ItemTemplate>
<SeparatorTemplate>
<div id="SeparatorDiv">
</div>
</SeparatorTemplate>
</asp:Repeater>
Profile"

C# Code behind:

protected void MySponsoredChildrenList_ItemDataBound(object sender,


RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem ||
e.Item.ItemType == ListItemType.Item)
{
// Stuff to databind
Button myButton =
(Button)e.Item.FindControl("ChildProfileButton");
myButton.CommandName = "ViewProfile";

}
protected void MySponsoredChildrenList_ItemCommand(object source,
RepeaterCommandEventArgs e)
{
if (e.CommandName == "ViewProfile")
{
int ChildIDQuery =
Convert.ToInt32(e.Item.FindControl("ChildID"));
Response.Redirect("~/ChildDescription.aspx?ID=" + ChildIDQuery);
}
}

You might also like