الثلاثاء، 17 مارس 2009

Synchronize Data in Secondary User Control(s) Based Upon User Selections

This code shows how to create two DropDownList controls where selecting an item in the first list populates the items in the second list।


public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

if (!Page.IsPostBack)

{

DropDownList1.Items.Add(new ListItem("Select Country", "0"));

DropDownList1.Items.Add(new ListItem("Egypt", "1"));

DropDownList1.Items.Add(new ListItem("Saudi Arabia", "2"));

DropDownList2.Enabled = false;

}

}

public void GetGovernora(string index)

{

DropDownList2.Enabled = true;

switch (index)

{

case "1":

DropDownList2.Items.Clear();

DropDownList2.Items.Add(new ListItem("Cairo","1"));

DropDownList2.Items.Add(new ListItem("Alex","2"));

DropDownList2.Items.Add(new ListItem("Mansoura","3"));

DropDownList2.Items.Add(new ListItem("Domiatta","4"));

break;

case "2":

DropDownList2.Items.Clear();

DropDownList2.Items.Add(new ListItem("Ryiad","1"));

DropDownList2.Items.Add(new ListItem("Gada", "2"));

DropDownList2.Items.Add(new ListItem("Jezan", "3"));

break;

default:

DropDownList2.Items.Clear();

DropDownList2.Items.Add("No Avaliable Country");

DropDownList2.Enabled = false;

break;

}

}

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)

{

GetGovernora(DropDownList1.SelectedValue);

}

}


الأربعاء، 11 فبراير 2009

Text scroll effect

Text scroll effect

Introduction

In this tutorial, you will learn how to make a text scrolling effect using a label control. It's really quite simple, and it has a cool visual effect. To follow this tutorial step-by-step you will need .NET Framework and Visual Studio .NET installed on your machine.

Getting to work

Let's begin by creating a new C# Project using Visual Studio .NET. Select File -> New Project -> Visual C# Project -> Windows Application. Name your project however you want, I will call it TextScroll.

You are now in front of the Design view of your interface. First, we must create the user interface, after witch we will begin the coding part. The first thing we will do is add a Label control. To do that, select View -> Toolbox (or press Ctrl + Alt +X ). Select the Label control, drag and drop it onto our form. Now, we will need to adjust some properties of the Label. Select the Property window (if it's not visible, select View -> Properties Window, or just press F4). Change the TextAlign property to MiddleCenter ( by doing that, the text of the label will be displayed centered ). Also, the Text property of the label needs to display no text(from the Properties window, remove the text "label1", witch Visual Studio .NET adds it by default). It is preferred that we change the BackColor property (I changed it to SlateGray color, but you can use almost any color as long as the BackColor and ForeColor are different). Now change the ForeColor to LightSalmon. Let's add a Button for starting the scroll. Set its Text property to Start Scrolling and the Name to btn_start. The next thing we need to add is a TextBox control, to allow the user to input the string that he wants to scroll. Visual Studio .NET will name the TextBox to textBox1, we will change this Name to tb_scroll. Go to the Text property and remove "textBox1" string.

Another property we will need to change is MaxLength property to 30. This is the maximum number of characters that we allow the user to type into this control. The reason that we do this is that for a rather large number of characters, let's say 50, the label that we created earlier will display the text on two columns, making the scroll look rather ugly.

Put a Label control above the TextBox created earlier, and set the Text property to "Please enter the string to be scrolled:". For now, the design part is over.

After there steps, your form should look something like this:


Let's start creating some code, shall we?

Double-click the TextBox control. Visual Studio .NET created a method called tb_text_TextChanged. As its name says, this method occurs whenever the Text property of the TextBox changes. What we want to do is disable btn_start if we have no text in the TextBox. To do this, we need to add the following code:

if (tb_text.Text.Trim()="")

btn_start.Enabled = false;

else

btn_start.Enabled = true;

The Trim() method, called with no argument, removes the extra spaces from the beginning and the end of the text. If the text property of tb_text is "", we want btn_start to be disabled, else we enable it.

In the Design view, double-click the form's surface and a method called Form1_Load is created. In this method, we need to add the following:

btn_start.Enabled=false;
The reason we do this is that when our application starts, the TextBox has no text in it, and we want btn_start to be disabled, because we have no text to scroll.

Let's go back to Design view and double-click btn_start. Visual Studio will create a method called btn_start_Click. In this method we will write some code to begin the scrolling.

First, we must understand how this scrolling works. We have a string, let's say "string to test the scrolling effect ". To create the effect, we must remove the last character of the string and set the label's Text property to the new string "string to test the scrolling effect". Now we must place the removed character(' ') in the first position of the string, so that we have " string to test the scrolling effect". We must repeat this action until we have the same string that we had when we started. The steps are:

string to test the scrolling effect
string to test the scrolling effect
t string to test the scrolling effec
ct string to test the scrolling effe
ect string to test the scrolling eff
fect string to test the scrolling ef
ffect string to test the scrolling e
effect string to test the scrolling
effect string to test the scrolling
g effect string to test the scrollin
......................................................
string to test the scrolling effect

So we will have to create a function that executes the scrolling until the form is closed.

Now, we have to create a method that handles the scrolling, and call this method in the btn_start_Click method. Let's create the following method:

private void ScrollText()
{
}

Now we need to create the code that does the job.

System.Text.StringBuilder sb = new System.Text.StringBuilder(tb_text.Text+" ");

StringBuilder class helps up to manipulate strings. We call the constructor that takes a string that we will play with. The reason that a space is appended at the end of the text is to separate the last and the first character. We need this class' methods Insert (to insert the character we remove from the end at the beginning of the string ) and Remove ( to remove the last character from the string ).

while (true)
{

char ch = sb[sb.Length-1];
sb.Remove(sb.Length-1,1);
sb.Insert(0,ch);
label1.Text = sb.ToString();
label1.Refresh();
System.Threading.Thread.Sleep(100);

}

We do the scrolling until the user closes the window. We declare a variable of type char to hold the last character from the string,whitch we will remove using Remove() method. Next, we insert that character into the beginning of the string. We set the label text as the new text, refresh it and then we use the Sleep() method to pause the execution for 100 miliseconds. And that's the scroll.

All we have to do now is call the ScrollText() method in the btn_start_Click method. We also need to add some extra code:

btn_start.Enabled=false;
ScrollText();

Run the application and see this working.

The main problem of the application is a non-responsive user interface. That's because we do the scroll operation is performed on the same thread that the user interface function run on. To avoid this, we need to create an asynchronous delegate.

The first step is to declare a delegate at the beginning of the class and create an instance of it.

public delegate void ScrollDelegate();
private ScrollDelegate s_del;

The next step is to initialize it in the Form_Load method.

s_del = new ScrollDelegate(ScrollText);

Now, when we call the BeginInvoke() method of s_del, the scrolling will occur. We win call BeginInvoke() in the btn_start_Click method, replacing the call to ScrollText method.

s_del.BeginInvoke(null,null);

Let's run the application again now. You notice how improvement we've created by adding 4 lines of code?

Here is the application when I run it on my computer:

You can play around with the sleep interval(make the interval smaller to have a faster and smoother scroll, and make it bigger to have a "lazy" scroll).

Well, we've reached the end of this lesson. I hope you had as much fun as I did!

Attachments:

Project Files: TextScroll.जिप

Source

http://www.codersource.net/csharp_scrolling_text.aspx



الثلاثاء، 10 فبراير 2009

XML Document Object Model

الاثنين، 2 فبراير 2009

What Is the difference between Dataset and Datatable

What Is the difference between Dataset and Datatable
Yes , this is the questions i asked to any one who working with dis-connected model and no one answer me , What Is the difference between Dataset and Datatable ? , may be because some of people not show the desire to know things in deep and say as long as we do the required taks from us we not need to know what under things

Bascically , Dataset used when you want to cache all tables from your database into client memory , in the other hand DataTable also have the same mechanisme but used to cache only one table from your database into client memory

May be the answer is very easy but we not search :)
Thanks
Ahmed El Bohoty

الثلاثاء، 20 يناير 2009

What Is XSLT

What Is XSLT
XSLT is a declarative programming language, written in XML, for converting XML to some other
output. Often the output is XML or HTML, but in principle, XSLT can produce arbitrary output from any given XML source document

In a common scenario, two companies need to exchange XML documents electronically but for
historical reasons have differences in the structures of basic documents such as invoices and purchase orders

Procedural versus Declarative Programming

When using a procedural programming language such as JavaScript, you tell the computer what you
want to do step by step. You might define a function, and then define each thing that the computer is supposed to do, assigning a variable, iterating through a loop, and so on. The mental picture of what the function is supposed to achieve exists only in your mind

The procedural programming approach differs from declarative programming in that you tell the computer what you want to achieve. XSLT resembles SQL in that respect. For example, in SQL you tell the relational database management system (RDBMS) to SELECT certain columns, but you don’t expect to tell it how to retrieve the desired data. XSLT is similar. You specify what the XSLT processor is to create each time it comes across a particular pattern in the source tree

XSL - More Than a Style Sheet Language

XSL consists of three part

XSLT - a language for transforming XML documents

XPath - a language for navigating in XML documents

XSL-FO - a language for formatting XML documents


XSLT Uses XPath ...HOW ? PLZ GIVE ME CHANCE TO SAY HOW :) OK ..OK

XSLT uses XPath to find information in an XML document. XPath is used to navigate through elements and attributes in XML documents

 XSLT uses XPath to define parts of the source document that should match one or more predefined templates. When a match is found, XSLT will transform the matching part of the source document into the result document


In next article i will make simple example for XSLT and show its component ...Salam Alikm now

الاثنين، 19 يناير 2009

The Difference Between CSS and XSLT

The Difference Between CSS and XSLT
They're Both Style Sheets, Right? YES
Many people believe that CSS is for HTML and XSL or XSLT is for XML, but that's not strictly true. While both are style sheets, they serve two vastly different purposes

The reason is that CSS is much easier to use, easier to learn, thus easier to maintain and cheaper. There are WYSIWYG editors for CSS and in general there are more tools for CSS than for XSL. But CSS's simplicity means it has its limitations. Some things you cannot do with CSS, or with CSS alone. Then you need XSL, or at least the transformation part of XSL

What CSS Can Do
  • Modify the font size, color, family, and style of text in markup
  • Define the location and size of an element
  • Change the background image and color of elements
  • Create a new look and feel for markup pages to display on the Web

What CSS Cannot Do

  • Change the order of elements in a document
  • Make computations based on the content of the document
  • Add content to the document
  • Combine multiple documents into one

What XSLT Can Do

  • convert data in a standard XML format to SQL statements, tab-delimited text files, or other database formats for data sharing
  • transform XSLT style sheets into new style sheets
  • turn Web pages (written in XHTML) to VoiceML or XHTML Basic for handheld devices
  • add CSS style sheets to XML documents for view in a browser

If all you're looking for is a style sheet to manipulate the way your content looks in a document, then you should use CSS. But if you're looking to actually transform one document into another, then XSLT is your tool


Diagram of the role of XSL and CSS in rendering HTML and  XML documents

This diagram shows the role of XSL and CSS. XML documents can be rendered in three different ways: (1) if the document doesn't have to be transformed, use CSS. Otherwise, use XSL-T, the transformation language of XSL, in one of two ways: either (2)generate the style properties together with the rearranged text, using a sub-language of XSL called XSL-FO (XSL Formatting Objects); or (3) generate a new XML or HTML document and provide a CSS style sheet for that new document.

source

الجمعة، 16 يناير 2009

XPath Tutorial


To Read  More about the Expressions,Predicates and Functions  ==> Hit This Link

XPath
  To Read how to use XPath in .Net  ==> Hit This Link

 

السبت، 10 يناير 2009

XML Namespace

Namespace help to avoid conflict between two xml objects (xml data) of the same name.

In the following example we have 2 roots called table so how we can differentiate between them? And if you make search in your Xml document with the 2 same name how to determine the element you want!! So we can solve this problem by using namespace prefixes, follow this structure

First: 2 root with no namespace

Problem with prefix

After we differentiate between 2 Xml objects using prefix we also have a problem with prefix, imagine one of department of your company choose the same name for namespace like other department in the same company that choose the same name.

 

Solution

Use Uniform Resource Identifier by using URLThe purpose is to give the namespace a unique name. However, often companies use the namespace as a pointer to a web page containing namespace information

The namespace is defined by the xmlns attribute in the start tag of an element

The namespace declaration has the following syntax. xmlns:prefix="URI"


الاثنين، 5 يناير 2009

.Net Video

الجمعة، 2 يناير 2009

Benefits of XML Schemas

Benefits of XML Schemas
  • XML Schemas are created using basic XML, while DTDs utilize a separate syntax.
  • XML Schemas fully support the Namespace Recommendation.
  • XML Schemas enable you to validate text element content based on built-in and user-defined datatypes.
  • XML Schemas enable you to more easily create complex and reusable content models.
  • XML Schemas enable the modeling of programming concepts such as object inheritance and type substitution

 

97 Things Every Software Architect Should Know

 97Things Every Software Architect Should Know

The following are the 97 axioms selected for the book, 97 Things Every Software Architect Should Know, which will be published by O'Reilly Media in early 2009. The contents are now being edited for publishing - you can see them here. All edits will be contributed back to the 97 Things web site on this page.

read more
Here's agood blog that interested about software Architect