ASP.Net


If you have developed a web site project and you are forced to convert the same to web
Application. Then you can follow the steps mentioned Here..
This works perfect. It is converting the application without any error

Happy Coding

Hi All,

         In this I am going to explain some of the imports attributes of previouspage in asp.net 2.0 and above

  1. Back Button with the use of PreviousPage method

           You can move to the previous where you are redirected from by using the following method

          I have one button in my form with name called Button1 and the text property to set Back. And in the code behind i have code like this

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

Button1.PostBackUrl= PreviousPage.AppRelativeVirtualPath; 

}

Here I am setting the Postback url of the button as the previous page url. The

PreviousPage.AppRelativeVirtualPath

Will return the relative path of the previous page. And after getting this I am assinging it to the button control.

More to follow

I came to a situation where I wanted to Set a default button for my page. I struggeled to set so.Then i found that it could be also done in the design view itself ..

This is the form design view

myimage.jpg

To set the Default button set the default button of the form to the button you wish to set as default

<form id=”form1″ runat=”server” defaultbutton=”Button1″ >

and for the default focus set the default focus property of form tag to control that you wish as default focus. In this case i wanted to set the Textbox1 should have the default. So the code is

<form id=”form1″ runat=”server” defaultfocus=”txtName” >

and the entire coding is as

<form id=”form1″ runat=”server” defaultbutton=”Button1″ defaultfocus=”txtName” >

<asp:TextBox ID=”txtName” runat=”server” AutoPostBack=”false”></asp:TextBox>

<asp:Button ID=”Button1″ runat=”server” OnClick=”Button1_Click” Text=”Button” />

</form>

Happy Coding

Hi all,
Here I am going to display how to update the datatable to the underlaying sqltable….

I am using the VS2005 and SQL as the BackEnd

    Code for Updating the underlaying datatable

SqlCommand sqlcmd = new SqlCommand("Select * from customers"); //Using the northwhind
//SqlConnection is class which will open the connection to Northwind Database
sqlcmd.Connection = SQLConnections.sqlCon;
SqlDataAdapter sqda = new SqlDataAdapter(sqlcmd);
DataTable dtTemp = new DataTable();
SqlCommandBuilder sqlbuilder = new SqlCommandBuilder(sqda);
SQLConnections.OpenConnection();
sqda.Fill(dtTemp); //fill the values returned into temp data table
DataRow dr = dtTemp.NewRow(); //Creating a new row
dr["CustomerID"] = "100"; //Add the custumer id //Required
dr["CompanyName"] = "SolidSollutions"; //Adding the companyName
dr["ContactName"] = "Danasegarane";
dr["ContactTitle"] = "Programmer";
dr["Address"] = "India";
dr["City"] = "India";
dr["Region"] = "India";
//I have left other columns fields because they are not the mandatory one
dtTemp.Rows.Add(dr); //Adding the row to the datatable
sqda.Update(dtTemp); //Update the related dataadapeter
sqda.Dispose(); //dispose
SQLConnections.CloseConnection();

The SQLConnection Class which is used in the previous code

public class SQLConnections
{
public enum ReturnType { ExcuteNonQuery = 1, ExcuteScallar = 2, ExcuteReader = 3, ExcuteXMLReader = 4,ExcuteDatatable=5 };
public static SqlConnection sqlCon;
public static string strErrorDescription = string.Empty;
public static void OpenConnection()
{
string SQLServerName = string.Empty;
string SQLDataBase = string.Empty;
string SQLConnectionString = string.Empty;
SQLServerName = ConfigurationManager.AppSettings["SQLServerName"];
SQLDataBase = ConfigurationManager.AppSettings["SQLDataBase"];
SQLConnectionString += "data source=" + SQLServerName + ";";
SQLConnectionString += "initial catalog=" + SQLDataBase + ";";
SQLConnectionString += "user id=sa;Password=test;";
SQLConnectionString += "persist security info=True ";
sqlCon = new SqlConnection(SQLConnectionString);
try
{
if (sqlCon.State == ConnectionState.Closed)
{
sqlCon.Open();
}
}
catch (Exception ex)
{
strErrorDescription = ex.Message;
}
}

Hope this helps to some one

For more info Please refer : SQLCommandBuilder

This Article from Explains the process of exporting a datagrid to excel. Hope this helps to some one

How To Export Data in a DataGrid on an ASP . NET WebForm to Microsoft Excel

I found this article to maintain the checkbox state during paging in datagridview. This works well.

        Paging with Checkbox.

Hope this is useful to u