/* ------------------------ My Meta Content Here SEO ------------------------ */

Pages

Main Menu

Tuesday, October 11, 2011

Exporting Data Table OR Dataset from SQL Server to Microsoft Excel in ASP.NET Using C#

Exporting Data from SQL Server to Excel

Read More »

Saturday, October 1, 2011

ASP.NET SQL Server Registration Tool

Creating the Application Services Database for SQL Server

Using aspnet_regsql.exe

ASP.NET includes a tool for installing the SQL Server database used by the SQL Server providers, named Aspnet_regsql.exe. The Aspnet_regsql.exe tool is located in the drive:\WINDOWS\Microsoft.NET\Framework\versionNumber folder on your Web server. Aspnet_regsql.exe is used to both create the SQL Server database and add or remove options from an existing database.

The Aspnet_regsql.exe tool is located in the following folder:

C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_regsql.exe

Note *
The Aspnet_regsql tool should not be used with a local installation of SQL Server Express running in user instance mode (that is, the connection string contains User Instance=true).

Installing the Database using Aspnet_regsql.exe
You can also run the Aspnet_regsql.exe tool as a command-line utility. For example, the following command installs the database elements for membership and role management on the local computer running SQL Server:
aspnet_regsql.exe -E -S localhost -A mr
Read More »

Tuesday, September 27, 2011

Friday, September 23, 2011

Using data list in asp.net

How to use datalist in asp.net ?

Dynamically adding row in datalist using asp.net.

Here i am just showing you the code for that. Here we go for some brief description about it.
We have a datalist and a input control as inside the . Now we want add some more row at runtime with a footer option add more on it. So what to do now and how to do ?
Here is the code for that.

*********************** H e r e i s t h e d a t a l i s t ************************************

********************************************************************************
using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class frmdatalist : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Session["tblsession"] == null)
{
SetInitialRow();
}
}
}

///
/// First Set Data List Initial Row on page loading
///


private void SetInitialRow()
{
DataTable dt = new DataTable();
DataRow dr = null;
dt.Columns.Add(new DataColumn("University", typeof(string)));
dr = dt.NewRow();
dr["University"] = string.Empty;
dt.Rows.Add(dr);

//Store the DataTable in ViewState
ViewState["CurrentTable"] = dt;
DatalistUniversity_name.DataSource = dt;
DatalistUniversity_name.DataBind();
}


private void AddNewRowToGrid()
{
int rowIndex = 0;
if (ViewState["CurrentTable"] != null)
{
DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];
DataRow drCurrentRow = null;
if (dtCurrentTable.Rows.Count > 0)
{
for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
{

//extract the TextBox values
TextBox box1 = (TextBox)DatalistUniversity_name.Items[0].FindControl("txtUniversityName");
drCurrentRow = dtCurrentTable.NewRow();
drCurrentRow["University"] = box1.Text;
rowIndex++;
}

//add new row to DataTable
dtCurrentTable.Rows.Add(drCurrentRow);
//Store the current data to ViewState
ViewState["CurrentTable"] = dtCurrentTable;
//Rebind the Data List with the current data
DatalistUniversity_name.DataSource = dtCurrentTable;
DatalistUniversity_name.DataBind();
}
else
{
Response.Write("ViewState is null");
}
//Set Previous Data on Postbacks.
SetPreviousData();
}
///
/// Set Previous Data in Data List.
///

private void SetPreviousData()
{
int rowIndex = 0;
if (ViewState["CurrentTable"] != null)
//Creating a new table to store the data of current table.
DataTable dtnew = (DataTable)ViewState["CurrentTable"];
if (dtnew.Rows.Count > 0)
{
for (int i = 1; i < dtnew.Rows.Count; i++)
{
TextBox box1 = (TextBox)DatalistUniversity_name.Items[i].FindControl("txtUniversityName");
box1.Text = dtnew.Rows[i]["University"].ToString();
rowIndex++;
}
}
}
}

protected void btnAddUniversityName_Click(object sender, EventArgs e)
{
AddNewRowToGrid();
int rowindex = 0;
Int32 total = 0;
for (int i = 1; i < DatalistUniversity_name.Items.Count; i++)
{
TextBox box1 = (TextBox)DatalistUniversity_name.Items[i].FindControl("txtUniversityName");
total = Convert.ToInt32(box1.Text) + Convert.ToInt32(total);
rowindex++;
}
txtsum.Text = Convert.ToString(total);
}
}

You Just Downlaod the code and review it you can do this my buddy you are the champ. you can do anything.
File1
File2
Read More »

Thursday, September 22, 2011

AutoPostBack Property in asp.net

AutoPostBack Property

What ? Autopostback is the mechanism, by which the page will be posted ,back to the server automatically based on some events in the web controls. In some of the web controls, the property called auto post back, which if set to true, will send the request to the server when an event happens in the control. If this property is set to TRUE the automatic post back is enabled, otherwise FALSE. "Default value of AutoPostBack property is FALSE."


Why  ? we need to set autopostback=true of controls?

Consider a scenario where the web page is used for entering the user information. The page contains two dropdownlist controls ddlcountry and ddlstate. When user selects the country, the appropriate states be filled in the ddlstate which is loaded from the database. For achieving this requirement, we can set the autopostback property of ddlcountry to true. If we do that we can handle the event in the server side and write code to populate the ddlstate with the values from the database.
This is how we use the autopostback property. 


Note* By default the button,linkbutton and imagebutton has an autopostback as an event. The code behind that you write is to handle this postback. A button cannot have an explicit button postback but is in-built.
Read More »

My Blog List