Formatting Sitemap files in VS.Net

Sometimes, when creating sitemap files, it’s hard to get good formatting, since the right-click/format page item is not accessible there.

So, in order to do this, just:

  • Select All
  • Cut all the data to the clipboard
  • Paste it back in the file

Voila – it’s perfectly formatted!

How to center a table using CSS

I know this is not exactly a .Net tip, but many of us have run into the need for it. Now that ‘align=center’ has been deprecated, you might be wondering how to get a table centered on the page.

First, create a class in your css document:

table.center
{
margin-left:auto;
margin-right:auto;
}
Then, inside your table tag, just put assign the center class:

<table 
class="center">

How to Load mulitple files in a frameset?

Scenario:

You have Multiple file paths to be loaded in a iframe. But the
last file alone is getting loaded. What happened to the other files?

Solution:

If we use only one iframe to load more files, each and every time the URL is overridden by the successive URL.

Ex:

for(i=0;i<n;i++)

{

sURL = "value obtained from some other source";

window.frames["iframeID"].location.href = sURL;

}

In orde to overcome this issue, we need to create seperate frame for each URL.

for(i=0;i<n;i++)

{

sURL = "value obtained from some other source";

sFrameID = "Frame" + Math.random();
CreateDynamicFrame(sFrameID,sURL);

}

function CreateDynamicFrame(sFrameID,sURL)

{
var NewiFrame = document.createElement("iframe");

NewiFrame.id= sFrameID;

NewiFrame.width = "100%";

NewiFrame.height = "100%";

NewiFrame.src = sURL;

NewiFrame.visible = "false";

document.body.appendChild(NewiFrame);

}

In this case, each URL is loaded properly.

Copying/Renaming file in project

Let’s say you want to rework a file, with new code, but possibly using some or all of the same methods. Therefore, you copy the file, and paste the new one back into the project, renaming it (using VS.Net), figuring that you can work on it over time and not affect your production code.

Remember that, even though you have renamed the file, the code behind class does not get renamed. Therefore, when published, you will have ambiguous code using the same class name. This can possibly give you some strange looking errors that might be hard to track down. One in particular, which might be thrown is the dreaded “‘InitializeCulture’ is not a member of …” followed by your filename.

Going back into the code behind and renaming the class, and then changing the class name in the HTML page directive should fix this.

How to add dummy nodes to Treeview for testing

Figure out how many (let’s say 100 for this example) nodes you’d like to add.
Then, add code similarly, in your Page_Load event:

Dim x as integer    For x=1 to 100          Dim nd as Treenode=new Treenode            nd.Text="Node" & x          nd.value="Node" & x          Treeview1.Nodes.add(nd)     Next

That’s it – - if you want to add subnodes, you can add a recursive routine to add subnodes for each of the above nodes added.                       

Image in DataList with scrollbar

Normal
0

false
false
false

MicrosoftInternetExplorer4

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:”Table Normal”;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:”";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:”Times New Roman”;
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}

Create a file Handler.ahx

 

 

<%@ WebHandler
Language=”C#”
Class=”Handler”
%>

 

using
System;

using
System.Data;

using
System.Configuration;

using
System.Collections;

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;

using
System.Data;

using
System.Data.SqlClient;

using
System.IO;

public
class Handler : IHttpHandler

{

 

    public void ProcessRequest(HttpContext
context)

    {

 

        SqlConnection
myConnection = new
SqlConnection(ConfigurationSettings.AppSettings["connection"].ToString();

        myConnection.Open();

        string sql = “Select * from
guest.Photos where Pic_ID=@Pic_ID“;

        SqlCommand cmd = new SqlCommand(sql,
myConnection);

        cmd.Parameters.Add(“@Pic_ID”,
SqlDbType.Int).Value = context.Request.QueryString["id"];

Delete a slected row from a DataGrid using c#

Hi..

Double click the dataGrid and write the code

private void DataGridvie_selected(Object sender,EventArgs e)
{
DataSet da=new DataSet();
//when you select a row that index will storing in i variable
int i=datagrid1.selectedIndex;

int empidval=ds.Tables["emp"].Rows[i][0].ToString();
//above what you had selected that row value exa:empid has 101 is stored in empidval vairable

//write the delete query

SqlConnection conn=new Sqlconnection(“conn string”);
conn.Open();
SqlCommand cmd=new SqlCommand(“delect emp where empid=”+empid+”",conn);
cmd.ExecuteNonQuery();
MessageBox.Show(“Row Deleted“);
}

Passing a Value From One Page to Another Page using c#

Hi..first page value in second page

create one New class as A


Class A
{

//int that decalare a variable as username

pubilic static string username=”shakeer”;

}

which page you want username you can use it.

Class B
{
//suppose you want to display username in a txtbox1

textusername.Text=A.username;

}

//Static variable can be accessed with the class Name itself..

so..without using Session,Cookies..you can pass value to another page by using static variable