Posts Tagged ‘OLDPOST’

Use DIVs to layout grid form controls in ASP.Net

March 24th, 2009 Comments off

It is interesting that people tend to usie tables to layout contents in a Page, or controls in ASP page. Because this may be one of the easiest way to do the layout job quick. However to restruct the layout is always a headache.

I guess in the most typical page layout is form, it consists of labels controls, textboxes, dropdown boxes, and sometimes datagrids etc. I prefer to use DIV blocks to control layouts instead of table.

I use the stylesheet to class the div tags, an example is below:

in file:mycss.css

DIV.base-layer {
background: none ; border:
margin: 0.5em 12px 0.5em 12px; padding: 0; text-align: center; width: 80%;}
DIV.table-row {
margin-top: 0; margin-right: auto; margin-bottom: 0; margin-left: auto;}
DIV.left-cell41 {
border: none; float: left;border: thin solid red 1px; margin: 0; padding: 0; width: 20%;}
DIV.left-cell42 {
border: none; float: left;border: thin solid blue 1px; margin: 0; padding: 0; width: 30%;}
DIV.left-cell43 {
border: none; float: left;border: thin solid green 1px; margin: 0; padding: 0; width: 20%;
DIV.left-cell44 {
border: none; float: left;border: thin solid yellow 1px; margin: 0; padding: 0; width: 29%;

in mysample.html (or you can put that in aspx)

<style type=”text/css”>@import url(mycss.css);</style>
<div class=”base-layer”>
   <div class=”table-row” >
        <div class=”left-cell41″>cell1</div>
        <div class=”left-cell42″>cell2</div>
        <div class=”left-cell43″>cell3</div>
  <div class=”left-cell44″>Last cell</div>

However there is still a problem with overflowing, when the text in the cell is over the size of the cell, the text draws outside the box.
I am still doing research to seek for solution

Categories: ASP, Tech Tags: , , ,

C# function parameters passing

March 24th, 2009 Comments off

Yes, C# doesn’t support variable number of parameters in function signature,
by default, according to MSDN, the parameters passed by value:

A parameter declared with no modifiers is a value parameter. A value parameter corresponds to a local variable that gets its initial value from the corresponding argument supplied in the method invocation.

But there is something more interesting than that:

ref keyword: pass the value of the parameter into the function body by reference.

void addme(ref int i){
...... in some function body..
i = 10;
Console.WriteLine(i); /// output 11;

out keyword: sometimes a single retrurn is not enough; why not use the input parameter as return value container? the parameter specifies with out keyword doen’t need to be initialize.
params keyword: A parameter declared with a params modifier is a parameter array. If a formal parameter list includes a parameter array, it must be the last parameter in the list and it must be of a single-dimensional array type. For example, the types string[] and string[][] can be used as the type of a parameter array, but the type string[,] cannot. It is not possible to combine the params modifier with the modifiers ref and out.

using System;
class Test
static void F(params int[] args) {
Console.Write(”Array contains {0} elements:”, args.Length);
foreach (int i in args)
Console.Write(” {0}”, i);
static void Main() {
int[] arr = {1, 2, 3};
F(10, 20, 30, 40);

Output is
Array contains 3 elements: 1 2 3
Array contains 4 elements: 10 20 30 40
Array contains 0 elements:
For details you can refer to MSDN document HERE

Categories: C#, Tech Tags: , ,