www.kevincornwell.com

Archive



How to dynamically add a table row with input fields in .NET.

C# using Visual Studio 2005…

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;
 
public partial class _Default : System.Web.UI.Page 
{
    // How many rows when the page initially loads.
    static int tDefaultRow_Count = 10;
    // Max number of rows.
    static int tMaxRows = 50;
 
    // Do not modify the following.
    private int tUserAddedRowCount = 0;
    static TextBox[] TextBox_Item = new TextBox[tMaxRows];
    static TextBox[] TextBox_Desc = new TextBox[tMaxRows];
    static TextBox[] TextBox_Quantity = new TextBox[tMaxRows];
    static TextBox[] TextBox_Price = new TextBox[tMaxRows];
    static TextBox[] TextBox_Total = new TextBox[tMaxRows];
 
    protected void Page_Load(object sender, EventArgs e)
    {
        tUserAddedRowCount = (ViewState["tUserAddedRowCount"] != null) ? int.Parse(ViewState["tUserAddedRowCount"].ToString()) : 0;
        //Response.Write("User Rows: " + tUserAddedRowCount + "\r\n");
 
        // Recreate the extra rows created by the user on postback
        // events (required to maintain state).
        Add_Table_Rows(tUserAddedRowCount + tDefaultRow_Count);
    }
 
    protected void Button1_Click(object sender, EventArgs e)
    {
            // User clicked "add a row" button.
 
            Add_Table_Rows(1);
            ViewState["tUserAddedRowCount"] = ++tUserAddedRowCount;
    }
 
    protected void Button2_Click(object sender, EventArgs e)
    {
        // User clicked "Submit" button.
 
        for (int x = 0; x < tDefaultRow_Count + tUserAddedRowCount; x++)
        {
 
            if (TextBox_Item[x].Text.ToString().Length > 0) 
            { 
                Response.Write(TextBox_Item[x].Text.ToString());
                Response.Write(TextBox_Desc[x].Text.ToString());
                Response.Write(TextBox_Quantity[x].Text.ToString());
                Response.Write(TextBox_Price[x].Text.ToString());
                Response.Write(TextBox_Total[x].Text.ToString());
            }
        }
    }
 
    private void Add_Table_Rows(int NumberOfRows)
    {
        for (int x = 0; x < NumberOfRows; x++)
        {
            TableRow myRow = new TableRow();
            Table1.Rows.Add(myRow);
 
            TableCell myCell0 = new TableCell();
            myRow.Cells.Add(myCell0);
            TextBox myTextbox0 = new TextBox();
            TextBox_Item[x] = myTextbox0;
            myCell0.Controls.Add(TextBox_Item[x]);
 
            TableCell myCell1 = new TableCell();
            myRow.Cells.Add(myCell1);
            TextBox myTextbox1 = new TextBox();
            TextBox_Desc[x] = myTextbox1;
            myCell1.Controls.Add(TextBox_Desc[x]);
 
            TableCell myCell2 = new TableCell();
            myRow.Cells.Add(myCell2);
            TextBox myTextbox2 = new TextBox();
            TextBox_Quantity[x] = myTextbox2;
            myCell2.Controls.Add(TextBox_Quantity[x]);
 
            TableCell myCell3 = new TableCell();
            myRow.Cells.Add(myCell3);
            TextBox myTextbox3 = new TextBox();
            TextBox_Price[x] = myTextbox3;
            myCell3.Controls.Add(TextBox_Price[x]);
 
            TableCell myCell4 = new TableCell();
            myRow.Cells.Add(myCell4);
            TextBox myTextbox4 = new TextBox();
            TextBox_Total[x] = myTextbox4;
            myCell4.Controls.Add(TextBox_Total[x]);
 
        }
    }
}

Post Comment Now


SQL Injection Cheat Sheet

Better to know what the bad guys are up to than not.

SQL Injection Cheat Sheet


Post Comment Now


Run php 4.x and php 5.2.x on the same machine with IIS 6.0 as ISAPI.

Run php 4 and php 5.2.x on the same machine with IIS 6.0 as ISAPI.

  1. Extract the ZIP packages of both php 4 & php 5 (not the Windows Installer) to c:\php4 & c:\php5 respectively.
  2. Setup the corresponding php.ini files in c:\php4 and c:\php5
  3. Add the Web Service Extensions for php4 and php5. For php4 use c:\php4\sapi\php4isapi.dll, php5 use c:\php5\php5isapi.dll
  4. Add the following registry keys:
    HKEY_LOCAL_MACHINE\SOFTWARE\PHP\5\IniFilePath -> c:\php5
    HKEY_LOCAL_MACHINE\SOFTWARE\PHP\IniFilePath -> c:\php4
    
  5. Add c:\php4 to the PATH environment variable.
  6. Add c:\php5 to the PATH environment variable.
  7. Associate each web site in IIS with the corresponding php version.
  8. Reboot.

Note: In IIS you still need to to have the DLL’s in the “Allowed Web Service Extensions List” and the extensions in the appropriate “Application Configuration” settings for the given websites/applications.

Read more…


Post Comment Now


HTML PowerPoint presentation running from a secure SharePoint site prompts with a “unsecured” dialog.

This post has been moved to mySharePointBlog. Go Here.


Comments Off


Comet – High Speed AJAX

Basic Definitions of Comet:
Wiki

Server Technologies:

IE will not allow your to read xmlhttp.responseText untill xmlhttp.readyState = 4 (complete — connection closed). It works in FF.

var http_request = false;  
function makeRequest(url) {
 	http_request = false;
 	if (window.XMLHttpRequest) { // Mozilla, Safari,...
 		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
 			http_request.overrideMimeType('text/xml');
 			// See note below about this line
 		}
 	} else if (window.ActiveXObject) { // IE
 		try { //
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
        		http_request = new ActiveXObject("Microsoft.XMLHTTP");
 		} catch (e) {
 			try {
 				http_request = new ActiveXObject("Microsoft.XMLHTTP");
 			} catch (e) {} 		}
 	}
 	if (!http_request) {
 		alert('Giving up :( Cannot create an XMLHTTP instance');
 		return false;
 	}
 	http_request.onreadystatechange = alertContents;
 	http_request.open('GET', url, true);
 	http_request.send(null);
  }
  var i = 0; var str = "";
  function alertContents() {
 	$('info').innerHTML = '<h3>'+ Date() + ' ' + http_request.readyState +':</h3>' + http_request.responseText;
 	if (http_request.readyState == 4) {
 		$('info').innerHTML = '<h1>Complete ('+ http_request.status +'):</h1>' + http_request.responseText;
 	}
 }
  function $() {
     var elements = new Array();
     for (var i = 0; i < arguments.length; i++) {
       var element = arguments[i];
       if (typeof element == 'string') {
         if (document.getElementById) {
           element = document.getElementById(element);
         } else if (document.all) {
           element = document.all[element];
         }
       }
       elements.push(element);
     }
     if (arguments.length == 1 && elements.length > 0) {
       return elements[0];
     } else {
       return elements;
     }
 }
function go(){ 	makeRequest('http://www.kevincornwell.com/comet/x-mixed-replace.php'); }

Post Comment Now


Blog | Contact | Gallery | Links | Google Latitude (location) | Music | Sandbox | Search | SharePoint | Social Networking | Software | Weather | Web Design


Copyright © 1997-2009 KCSH. All rights reserved.