Archive for August 16th, 2007

Load XML file in PHP

Thursday, August 16th, 2007

class doc

{

bool load_doc ( string filename )

}

Loads and XML document from a file.

Examples:

 

<?php
$document1
= DOMDocument::load(‘example.xml’);
echo
$document1->saveXML();

$document1 = new DOMDocument();
$docoument1->load(‘book.xml’);
echo
$document1->saveXML();
?>

Posted By:V.Mahesh

Posted by Mahesh ( Tryangled )

Troubleshooting Cofiguration Error in asp.net?

Thursday, August 16th, 2007
  1. step1: Select Control Panel->Administrative Tools->run internet Service Manager
  2. Find the project in the list of projects. (Open up your computer in the list and look under “Default Web Site”).
  3. Bring up its properties (Right click > Properties).
  4. If the “application name” (under “Application Settings” on the “Directory” tab) is greyed out then click ‘[Create]’ and then ‘[OK]’.

Posted By: V.Mahesh

Posted by Mahesh ( Tryangled )

selecting checkbox insiding gridview control in asp.net

Thursday, August 16th, 2007

stringBuilder name=new stringBuilder();

//select checkbox from gridview control

for (int i = 0; i < GridView1.Rows.Count; i++){

GridViewRow row_names = GridView1.Rows[i];

bool isChecked = ((CheckBox) row_names.FindControl(“chkSelect”)).Checked;

if (isChecked)

{


str.Append(GridView1.Rows[i].Cells[2].Text);

}

}

//Results

Response.Write(str.ToString());

<HeaderTemplate>
<input id=”cheackall” onclick=”javascript:selectcheckbox(this);” runat=”server” type=”checkbox” />
</HeaderTemplate>


<script language=javascript>

function selectcheckbox(chk){

var item1 = Chk.children;

var theBox=(Chk.type==“checkbox”)?Chk:Chk.children.item[0];

xState=theBox.checked;

elm=theBox.form.elements;

for(i=0;i<elm.length;i++)

if(elm[i].type==“checkbox” && elm[i].id!=theBox.id)

{

//elm[i].click();

if(elm[i].checked!=xState)

elm[i].click();

//elm[i].checked=xState;

}

}

</script>

Posted By: V.Mahesh

Posted by Mahesh ( Tryangled )

how to rewriting URL in asp.net?

Thursday, August 16th, 2007

void Application_BeginRequest(Object sender,EventArgs e)

{

string cpath;

 	String CustomPath;

 	Cpath = Request.Path;

	 cPath = cPath.ToLower();

 if (cPath.IndexOf( “/subfolder/” ) > -1)

 {

  CustomPath = “getContent.aspx?id=” +

Path.GetFileNameWithoutExtension( cPath );  // rewrite the URL

  Context.RewritePath( cPath );

 }

}



Posted By:V.Mahesh
Posted by Mahesh ( Tryangled )

Dynamic Progress page for ASP.NET

Thursday, August 16th, 2007

Example for create dynamic progress page for asp.net as follows.

private void Page_Load(object sender, System.EventArgs e)
{

Response.Write(”

    “);
    WebClient wc= new WebClient();
    for(int i= 1; i<40;i++)
    {
    byte[] b=wc.DownloadData(”http://www.tryangled.com”);
    Response.Write(”

  • tryangled solutions ” + i.ToString()+” Length: ” + b.Length.ToString());
    }
    Response.Write(”

“);
}

Posted By:V.Mahesh

Posted by Mahesh ( Tryangled )

How to select particular row in Gridview control?

Thursday, August 16th, 2007

Gets or sets the index of the selected row in a Grid View control.Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

Examples:

Code:[VB.NET]

<%@ Page language=“VB” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
    “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<script runat=“server”>

  Sub CustomersGridView_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)

    ‘ Get the currently selected row using the SelectedRow property.
    Dim row As GridViewRow = CustomersGridView.SelectedRow

    ‘ Display the company name from the selected row.
    ‘ In this example, the third column (index 2) contains
    ‘ the company name.
    Message.Text = “You selected “ & row.Cells(2).Text & “.”

  End Sub

  Sub CustomersGridView_SelectedIndexChanging(ByVal sender As Object, ByVal e As GridViewSelectEventArgs)

    ‘ Get the currently selected row. Because the SelectedIndexChanging event
    ‘ occurs before the select operation in the GridView control, the
    ‘ SelectedRow property cannot be used. Instead, use the Rows collection
    ‘ and the NewSelectedIndex property of the e argument passed to this 
    ‘ event handler.
    Dim row As GridViewRow = CustomersGridView.Rows(e.NewSelectedIndex)

    ‘ You can cancel the select operation by using the Cancel
    ‘ property. For this example, if the user selects a customer with 
    ‘ the ID “ANATR”, the select operation is canceled and an error message
    ‘ is displayed.
    If row.Cells(1).Text = “ANATR” Then

      e.Cancel = True
      Message.Text = “You cannot select “ + row.Cells(2).Text & “.”

    End If

  End Sub

</script>

<html  >
  <head runat=“server”>
    <title>GridView Select Example</title>
</head>
<body>
    <form id=“form1″ runat=“server”>

     <h3>GridView Select Example</h3>

     <asp:gridview id=“CustomersGridView”
       datasourceid=“CustomersSource”
       autogeneratecolumns=“true”
       autogenerateselectbutton=“true”
       allowpaging=“true”
       selectedindex=“0″
       onselectedindexchanged=“CustomersGridView_SelectedIndexChanged”
       onselectedindexchanging=“CustomersGridView_SelectedIndexChanging”
       runat=“server”>

       <selectedrowstyle backcolor=“LightCyan”
         forecolor=“DarkBlue”
         font-bold=“true”/>  

     </asp:gridview>

      <br/>

      <asp:label id=“Message”
        forecolor=“Red”
        runat=“server”/>

      <!– This example uses Microsoft SQL Server and connects  –>
      <!– to the Northwind sample database. Use an ASP.NET     –>
      <!– expression to retrieve the connection string value   –>
      <!– from the Web.config file.                            –>
      <asp:sqldatasource id=“CustomersSource”
        selectcommand=“Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]”
        connectionstring=“<%$ ConnectionStrings:NorthWindConnectionString%>”
        runat=“server”/>

    </form>
  </body>
 
</html>
 
 
 
Code:[C#.NET]
 
<%@ Page language=“C#” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
    “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<script runat=“server”>

  void CustomersGridView_SelectedIndexChanged(Object sender, EventArgs e)
  {

    // Get the currently selected row using the SelectedRow property.
    GridViewRow row = CustomersGridView.SelectedRow;

    // Display the company name from the selected row.
    // In this example, the third column (index 2) contains
    // the company name.
    Message.Text = “You selected “ + row.Cells[2].Text + “.”;

  }

  void CustomersGridView_SelectedIndexChanging(Object sender, GridViewSelectEventArgs e)
  {

    // Get the currently selected row. Because the SelectedIndexChanging event
    // occurs before the select operation in the GridView control, the
    // SelectedRow property cannot be used. Instead, use the Rows collection
    // and the NewSelectedIndex property of the e argument passed to this 
    // event handler.
    GridViewRow row = CustomersGridView.Rows[e.NewSelectedIndex];

    // You can cancel the select operation by using the Cancel
    // property. For this example, if the user selects a customer with 
    // the ID “ANATR”, the select operation is canceled and an error message
    // is displayed.
    if (row.Cells[1].Text == “ANATR”)
    {

      e.Cancel = true;
      Message.Text = “You cannot select “ + row.Cells[2].Text + “.”;

    }

  }

</script>

<html  >
  <head runat=“server”>
    <title>GridView Select Example</title>
</head>
<body>
    <form id=“form1″ runat=“server”>

     <h3>GridView Select Example</h3>

     <asp:gridview id=“CustomersGridView”
       datasourceid=“CustomersSource”
       autogeneratecolumns=true
       autogenerateselectbutton=true
       allowpaging=true
       selectedindex=“0″
       onselectedindexchanged=“CustomersGridView_SelectedIndexChanged”
       onselectedindexchanging=“CustomersGridView_SelectedIndexChanging”
       runat=“server”>

       <selectedrowstyle backcolor=“LightCyan”
         forecolor=“DarkBlue”
         font-bold=true/>  

     </asp:gridview>

      <br/>

      <asp:label id=“Message”
        forecolor=“Red”
        runat=“server”/>

      <!– This example uses Microsoft SQL Server and connects  –>
      <!– to the Northwind sample database. Use an ASP.NET     –>
      <!– expression to retrieve the connection string value   –>
      <!– from the Web.config file.                            –>
      <asp:sqldatasource id=“CustomersSource”
        selectcommand=“Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]”
        connectionstring=“<%$ ConnectionStrings:NorthWindConnectionString%>”
        runat=“server”/>

    </form>
  </body>
</html> 
Posted By: V.Mahesh


Posted by Mahesh ( Tryangled ) 				

Is there problem in maintaining session in subfolders?

Thursday, August 16th, 2007

session_save_path() returns the path of the current directory used to save session data.

use

session_save_path(”../”);

on the top of file in the subfolder one level down.

By this way the session can be maintained to all level of folders.

the other way is to change php.ini file . but most of servers will not allow to do so .

Courtesy : Research Result from Tryangled Solutions Pvt LtdĀ 

Posted by Suresh B