Click here to Skip to main content
15,895,423 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
C#
public void getdata()
   {



       txteno.Text = ds.Tables[0].Rows[rno][0].ToString();
       txtenme.Text = ds.Tables[0].Rows[rno][1].ToString();
       txtjob.Text = ds.Tables[0].Rows[rno][2].ToString();
       txtloc.Text = ds.Tables[0].Rows[rno][3].ToString();
       txtpno.Text = ds.Tables[0].Rows[rno][4].ToString();

   }


protected void Page_Load(object sender, EventArgs e)
    {
        string scon = ConfigurationManager.ConnectionStrings["scn"].ConnectionString;
        cn = new SqlConnection(scon);
        da = new SqlDataAdapter("select * from emphalf", cn);
        ds = new DataSet();
        da.Fill(ds, "emphalf");
        getdata();
}

protected void btnprev_Click(object sender, EventArgs e)
    {
        if (rno > 0)
        {
            rno -= 1;
            if (ds.Tables[0].Rows[rno].RowState == DataRowState.Deleted)
            {
                // DataRow dr = (DataRow)ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1];

                Response.Write("deleted row data cannot be accessed");
                return;

            }

            getdata();
        }

        else Response.Write("first record");
    }

protected void btnxt_Click(object sender, EventArgs e)
   {
       if (rno < ds.Tables[0].Rows.Count - 1)
       {
           rno += 1;
           if (ds.Tables[0].Rows[rno].RowState == DataRowState.Deleted)
           {
               Response.Write("deleted row data cannot be accessed");
               return;
           }
           getdata();

       }
       else Response.Write("last record");
    }


protected void btninsert_Click(object sender, EventArgs e)
    {
        DataRow dr = ds.Tables[0].NewRow();

        dr[0] = txteno.Text;
        dr[1] = txtenme.Text;
        dr[2] = txtjob.Text;
        dr[3] = txtloc.Text;
        dr[4] = txtpno.Text;

        ds.Tables[0].Rows.Add(dr);
        rno = ds.Tables[0].Rows.Count - 1;
        Response.Write("data row is added");
        getdata();

    }

protected void btnupdate_Click(object sender, EventArgs e)
   {
       ds.Tables[0].Rows[rno][1] = txtenme.Text;
       ds.Tables[0].Rows[rno][2] = txtjob.Text;
       ds.Tables[0].Rows[rno][3] = txtloc.Text;
       ds.Tables[0].Rows[rno][4] = txtpno.Text;
       Response.Write("data row is updated");
       getdata();


   }
   protected void btndelete_Click(object sender, EventArgs e)
   {
       ds.Tables[0].Rows[rno].Delete();

       Response.Write("data row is deleted");
       getdata();

   }

   protected void btnsave_Click(object sender, EventArgs e)
   {
       cb = new SqlCommandBuilder(da);
       da.Update(ds, "emphalf");

       Response.Write("data is saved to database");
       getdata();
   }
Posted
Comments
Tejas Vaishnav 18-Jan-14 5:48am    
and where is your question?
what issue you have faced?
JoCodes 19-Jan-14 22:42pm    
And what control you intend to show the list of data?

1 solution

Insted of using Gridview you can use repeater or Datalist
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900