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

Pages

Main Menu

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 »

Saturday, September 17, 2011

Triggers in sql server 2005

Some useful query related to Trigger in SQL SERVER 2005


***** how to create triggers in sql server 2005 ? *****


Create trigger your_trigger_name ON your_table_name
FOR Your_Operation -- For example : For Update or For Insert, For Delete, After Update, After Insert etc
AS
BEGIN
-- Your Input Output Parameter Declaration
SELECT @PARA1 = (COLUMN_NAME) FROM INSERTED
SELECT @PARA2 = (COLUMN_NAME) FROM DELETED
-- Your DATA Manipulation Operation Here
INSERT, UPDATE , DELETE
END
GO

Example Here:
 
FOR UPDATE TRIGGER IN SQL SERVER 2005


CREATE TRIGGER AfterUpdateTriggerTest ON TriggerTblCustomer
FOR UPDATE
AS
DECLARE @field AS INT
DECLARE @field1 AS VARCHAR(100)
BEGIN
    SELECT @field = (PKCUSTID) FROM INSERTED
    SELECT @field1 = (FNAME) FROM INSERTED
    UPDATE S SET name = @field1
    FROM TriggerTblSalesman AS S
    JOIN TriggerTblCustomer AS C
    ON C.PKCUSTID = S.FKCUSTID WHERE C.PKCUSTID = @field
END
GO



***** Search trigger text in SQL Server 2005 *****


SELECT text FROM syscomments WHERE [text] LIKE '%trigger%' AND
-- if you want a trigger attached to specific table then
[text] LIKE '%On your_trigger_name%'


SP_HELPTEXT your_trigger_name


***** Find all triggers in database *****

SELECT * FROM sys.triggers

***** Delete trigger from database *****

DROP TRIGGER your_trigger_name
Read More »

My Blog List

  • काश - काश मुझे भी पीने की आदत होती,मैं कब का मुर्दा हो गया होता। छुटकारा मिलता आज के आतंकवाद से, किसी संतान भूमि में सो गया होता। मेरा एतबार कौन करेगा, मैंने मुर...
    2 months ago
  • काश - काश मुझे भी पीने की आदत होती,मैं कब का मुर्दा हो गया होता। छुटकारा मिलता आज के आतंकवाद से, किसी शमशान भूमि में सो गया होता। मेरा एतबार कौन करेगा, मैंने मुर...
    2 months ago
  • Kumaon University Nainital B.Ed entrance exam test result 2012 - कुमाऊँ विश्वविधालय, नैनीताल (उत्तराखण्ड)
    10 years ago