Nitin Dhiman. Powered by Blogger.

get data from xml file.

No comments
call following function:


public void abc()
{
StreamReader stream1 = new StreamReader("C:\\Inetpub\\wwwroot\\PR\\TreeNormal\\books.xml");
XmlTextReader reader = null;
reader = new XmlTextReader(stream1);

while (reader.Read())
{
// Do some work here on the data.
switch (reader.NodeType)
{
case XmlNodeType.Element: // The node is an Element.
Response.Write("<" + reader.Name);
Response.Write(">
");
break;
case XmlNodeType.Text: //Display the text in each element.
Response.Write("
" + reader.Value);
break;
case XmlNodeType.EndElement: //Display end of element.
Response.Write(" Response.Write(">
");
break;
}

//Response.Write(reader.Name + " ");
}

while (reader.Read())
{
// Do some work here on the data.
//Console.WriteLine(reader.Name);
Response.Write(reader.Name);
}



}

Bind TreeView to sql database.

No comments
Call the following function in page_load event:


void fill_Tree()
{
//Database db = DatabaseFactory.CreateDatabase("ConStr");
//string sqlCommandName = "Select * from ParentTable";
//DbCommand dbCmd = db.GetSqlStringCommand(sqlCommandName);
//SqlDataReader Sdr = dbCmd.ExecuteReader();

/ SqlCon = new SqlConnection("Data Source=DATABASENAME;Initial Catalog=GKTraining;Persist Security Info=True;User ID=USERID;Password=gK@t#a!n!^T)");

SqlCon.Open();

/*
* Query the database
*/

SqlCommand SqlCmd = new SqlCommand("Select * from a_tbl_parent", SqlCon);

/*
*Define and Populate the SQL DataReader
*/

SqlDataReader Sdr = SqlCmd.ExecuteReader();

/*
* Dispose the SQL Command to release resources
*/

SqlCmd.Dispose();

/*
* Initialize the string ParentNode.
* We are going to populate this string array with our ParentTable Records
* and then we will use this string array to populate our TreeView1 Control with parent records
*/

string[,] ParentNode = new string[100, 2];

/*
* Initialize an int variable from string array index
*/

int count = 0;

/*
* Now populate the string array using our SQL Datareader Sdr.

* Please Correct Code Formatting if you are pasting this code in your application.
*/

while (Sdr.Read())
{

ParentNode[count, 0] = Sdr.GetValue(Sdr.GetOrdinal("ParentID")).ToString();
ParentNode[count++, 1] = Sdr.GetValue(Sdr.GetOrdinal("ParentName")).ToString();

}

/*
* Close the SQL datareader to release resources
*/

Sdr.Close();

/*
* Now once the array is filled with [Parentid,ParentName]
* start a loop to find its child module.
* We will use the same [count] variable to loop through ChildTable
* to find out the number of child associated with ParentTable.
*/

for (int loop = 0; loop < count; loop++)
{

/*
* First create a TreeView1 node with ParentName and than
* add ChildName to that node
*/

TreeNode root = new TreeNode();
root.Text = ParentNode[loop, 1];
root.Target = "_blank";

/*
* Give the url of your page
*/

root.NavigateUrl = "mypage.aspx";

/*
* Now that we have [ParentId] in our array we can find out child modules

* Please Correct Code Formatting if you are pasting this code in your application.

*/

SqlCommand Module_SqlCmd = new SqlCommand("Select * from a_tbl_child where ParentId =" + ParentNode[loop, 0], SqlCon);

SqlDataReader Module_Sdr = Module_SqlCmd.ExecuteReader();

while (Module_Sdr.Read())
{

// Add children module to the root node

TreeNode child = new TreeNode();

child.Text = Module_Sdr.GetValue(Module_Sdr.GetOrdinal("ChildName")).ToString();

child.Target = "_blank";

//child.NavigateUrl = "your_page_Url.aspx";
child.NavigateUrl = Module_Sdr.GetValue(Module_Sdr.GetOrdinal("ChildName")).ToString()+".aspx";

root.ChildNodes.Add(child);

}

Module_Sdr.Close();

// Add root node to TreeView
TreeView1.Nodes.Add(root);

}

/*
* By Default, when you populate TreeView Control programmatically, it expends all nodes.
*/
TreeView1.CollapseAll();
SqlCon.Close();

}

Asp calendar DayRender event.

No comments
Hi,

Here is the asp:calendar DayRender event example:



protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
string fontWeight = "normal";
if (isThereEvent(e.Day.Date))
fontWeight = "bold";

string color = "black";
if (e.Day.IsOtherMonth)
color = this.Calendar1.OtherMonthDayStyle.ForeColor.Name;

e.Cell.Text = String.Format("<a href="http://www.blogger.com/Default.aspx?day=%7B0:d%7D" style="text-decoration: none;">{1}</a>", e.Day.Date, e.Day.Date.Day);
}

private bool isThereEvent(DateTime date)
{
DateTime today = DateTime.Now;
DateTime tomorrow = today.AddDays(1);
DateTime anotherDay = today.AddDays(3);

// there are events today
if ((date.DayOfYear == today.DayOfYear) && (date.Year == today.Year))
return true;

// there are events tomorrow
if ((date.DayOfYear == tomorrow.DayOfYear) && (date.Year == tomorrow.Year))
return true;

// there are events on another day
if ((date.DayOfYear == anotherDay.DayOfYear) && (date.Year == anotherDay.Year))
return true;

return false;
}

Data Scraping.

No comments
Call following function for scraping:


protected void GetValueofFirstPage()
{
DataTable dt = new DataTable();
dt = CreateTable();
string strURL = "http://wsa2009.expoplanner.com/plsearch.wcs?searchby=all&seekword=null&alpha=all&filter=";
String strResult;
WebResponse objResponse;
WebRequest objRequest = HttpWebRequest.Create(strURL);
objResponse = objRequest.GetResponse();
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
{
//strResult = sr.ReadToEnd();

while ((strResult = sr.ReadLine()) != null)
{
if (strResult.Contains("Booth"))
{
flage = 1; ;
}
if (flage == 1)
{
if (strResult.Contains("href") && strResult.Contains("?"))
{
DataRow dr = dt.NewRow();
string[] str = strResult.Split('>');
string[] path = str[0].Split('\"');
str[1] = str[1].Replace("ANCHOR TAG END ~<~/~A~", "");
dr[0] = str[1];
dr[1] = "http://wsa2009.expoplanner.com/" + path[1];
dt.Rows.Add(dr);
Response.Write(str[1] + ' ' + path[1]);
Response.Write("LINE BREAK <~B~R~/~>");
//Session["dt"] = dt.ToString();
Session["dt"] = dt;
}
}
}

sr.Close();
flage = 0;
}
grd.DataSource = dt;
grd.DataBind();
}

Managing treeview in asp.net

No comments
TreeView1.Nodes.Clear();


TreeNode ndHome = new TreeNode("Home", "Home", "~/closebox.png", "~/Home.aspx", "");
TreeNode ndSplitter = new TreeNode("Splitter", "Splitter", "~/closebox.png", "~/Splitter.aspx", "");
TreeNode ndCheckPage = new TreeNode("Check Page", "Check Page",
"~/closebox.png", "~/CheckPage.htm", "");
TreeNode ndSearch = new TreeNode("Search", "Search", "~/closebox.png", "~/Search.aspx", "");
TreeNode ndAdvancedSearch = new TreeNode("Advanced Search", "Advanced Search",
"~/closebox.png", "~/AdvancedSearch.aspx", "");
TreeNode ndTxtChk = new TreeNode("TextBox", "TextBox", "~/closebox.png", "~/TextCheck.aspx", "");
TreeNode ndLogout = new TreeNode("Logout", "Logout", "~/closebox.png", "~/Logout.aspx", "");
TreeNode ndExtra = new TreeNode("Extra", "Extra", "~/closebox.png", "#", "");
TreeView1.Nodes.Add(ndHome);
TreeView1.Nodes[0].ChildNodes.Add(ndCheckPage);
TreeView1.Nodes.Add(ndSplitter);
//TreeView1.Nodes[0].ChildNodes.Add(ndAdvancedSearch);
TreeView1.Nodes.Add(ndSearch);
TreeView1.Nodes[2].ChildNodes.Add(ndAdvancedSearch);
TreeView1.Nodes.Add(ndLogout);
TreeView1.Nodes.Add(ndExtra);
TreeView1.Nodes[4].ChildNodes.Add(ndTxtChk);

Read data from xml file.

No comments
public void abc()
{
StreamReader stream1 = new StreamReader("C:\\Inetpub\\wwwroot\\PR\\TreeNormal\\books.xml");
XmlTextReader reader = null;
reader = new XmlTextReader(stream1);

while (reader.Read())
{
// Do some work here on the data.
switch (reader.NodeType)
{
case XmlNodeType.Element: // The node is an Element.
Response.Write("<" + reader.Name); Response.Write(">
");
break;
case XmlNodeType.Text: //Display the text in each element.
Response.Write("
" + reader.Value);
break;
case XmlNodeType.EndElement: //Display end of element.
Response.Write("
");
break;
}

//Response.Write(reader.Name + " ");
}

while (reader.Read())
{
// Do some work here on the data.
//Console.WriteLine(reader.Name);
Response.Write(reader.Name);
}
}

Incorporate Google Map to page.

No comments
SCRIPT START HERE src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAchOdSzCPe0fgAm8Ow24YYhQZMjxVy-0fy3B1JroJth17tbEUrRQwDlqM1PUlwiawvBO4RMVpYVIfLA"
type="text/javascript"
/SCRIPT END HERE

2ND SCRIPT TAG START HERE

var map = null;
var geocoder = null;

function load()
{
if (GBrowserIsCompatible())
{
map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(37.4419, -122.1419), 13);

geocoder = new GClientGeocoder();
var address =document.getElementById('TextBox1').value;

showAddress(address);
}
return false;
}
function showAddress(address)
{
if (geocoder)
{
geocoder.getLatLng(address,function(point) {
if (!point) {alert(address + " not Valid Address ");}
else {
map.setCenter(point, 13);

var baseIcon = new GIcon();
baseIcon.shadow = "images/star_location.gif";

baseIcon.iconSize = new GSize(19, 18);
baseIcon.shadowSize = new GSize(19, 18);
baseIcon.iconAnchor = new GPoint(9, 34);
baseIcon.infoWindowAnchor = new GPoint(9, 2);
function createMarker(point, index) {
// Create a lettered icon for this point using our icon class
var letter = String.fromCharCode("A".charCodeAt(0) + index);
var icon = new GIcon(baseIcon);
icon.image = "images/star_location.gif";
var marker = new GMarker(point, icon);

GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(address);});
return marker;
}

map.addOverlay(createMarker(point, 13));
}
}
);
}
}
/2ND SCRIPT TAG END HERE.


//DIV IN HTML PAGE

divSTART id="map" style="width: 600px; height: 600px;">
/divEND

//BUTTON BODY:

asp:button id="Button1" onclientclick="javascript:return load();" runat="server" text="Button"