Apr 10, 2016

Databound fields in GridView using Ado.net in asp.net C#

Hello there, here i m explaining how to use Databound fields using gridview .
Now first of all we will create a database.  Here the following script, copy it and run it.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tbEmp]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[tbEmp](
      [id] [int] IDENTITY(1,1) NOT NULL,
      [name] [varchar](50) NULL,
      [age] [int] NULL,
      [address] [varchar](50) NULL
) ON [PRIMARY]
END



Place the GridView control on a form and set the following property.
       AutoGenerateColumns="False"
And set the Gridview Events name is
onrowcancelingedit="GridView1_RowCancelingEdit"
onrowdeleting="GridView1_RowDeleting" onrowediting="GridView1_RowEditing"
onrowupdating="GridView1_RowUpdating"



Or add the default.aspx page and paste the following source code in it.


DataList Paging using ado.net in asp.net C#

In this article i am explaining how to do paging in datalist as we know datalist control does not support paging properties as Gridview control support. In this article i m displaying two images for paging and according to your requirement you can change it.  First of all create a database following the script which you can copy and paste it in your sql server 2005.

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tbStudent]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[tbStudent](
      [id] [int] IDENTITY(10,1) NOT NULL,
      [name] [varchar](50) NULL,
      [age] [int] NULL,
      [rollno] [int] NULL,
      [address] [varchar](50) NULL,
      [image] [varchar](50) NULL
) ON [PRIMARY]
END






Oct 8, 2010

How to create Temporary Table in asp.net with compute column in C#




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;

public partial class Default3 : System.Web.UI.Page
{
    Int32 tt;  // tt for total it will calculate the total
    DataTable tb = new DataTable(); //create a instance tb of Datatable

    protected void Page_Load(object sender, EventArgs e)
    {
// here we will create a temporary table of columns under ispostback.
        if (IsPostBack == false)
        {
//”ord” is a datatable type which create a “Table” and “c” for datatable columns.
            DataTable ord = new DataTable("Table"); //the “Table” value must be same for
            DataColumn c = new DataColumn();        // always
            ord.Columns.Add(new DataColumn("value", Type.GetType("System.Int32")));
// “value” is a column name with Int32 datatype.
            ord.Columns.Add(new DataColumn("length", Type.GetType("System.Int32")));
// “length” is a column name with Int32 datatype.
            ord.Columns.Add(new DataColumn("breadth", Type.GetType("System.Int32")));
// “total” is a column name with Int32 datatype.
            ord.Columns.Add(new DataColumn("total", Type.GetType("System.Decimal")));
// “total” is a Expression which calculate the following formula
            ord.Columns["total"].Expression = "value/(length*breadth)";
//storing the structure in “ss” name session.
            Session["ss"] = ord;
           
        }      
    }
    protected void btn_submit_Click(object sender, EventArgs e)
    {
        grdview();// will call the grdview method
    }

// following the temporary table with structure
    private void tempdata()
    {
        tb = (DataTable)(Session["ss"]); //getting the structure from session and
        GridView1.DataSource = tb; // storing in “tb” datatable variable and bind with
        GridView1.DataBind(); // gridview
        Int32 a; Int32 i; ;
        a = tb.Rows.Count; // it will count the total records in the temporary table
    

        for (i = 0; i < a; i++)
        {
            tt += Convert.ToInt32(tb.Rows[i][3]);// will sum the each value
        }
        Label1.Text = tt.ToString();// display in label the total values

    }