Tuesday, June 17, 2008

Edit ,Delete,Update in Gridview



    Untitled Page
    


    
update college/univercity name in COLLEGEPATH table:
<%#Eval("RegID")%> <%#Eval("companyname")%>
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;
using System.Data.SqlClient;

public partial class multieditepage : System.Web.UI.Page
{
    advReport adv = new advReport();
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!Page.IsPostBack)
        {

            this.DataBind1();
        }

    }

    protected void cancel(object sender, GridViewCancelEditEventArgs e)
    {
        dg.EditIndex = -1;
        this.DataBind1();
    }
    protected void edit(object sender, GridViewEditEventArgs e)
    {
        dg.EditIndex = e.NewEditIndex;
        this.DataBind1();
    }
    protected void update(object sender, GridViewUpdateEventArgs e)
    {
        string regid = ((TextBox)(dg.Rows[e.RowIndex].FindControl("txtreg"))).Text;
        string name = ((FileUpload)(dg.Rows[e.RowIndex].FindControl("upfile"))).FileName;
       
            adv.updateevents(regid, name);
            dg.EditIndex = -1;
            this.DataBind1();
     
    }
   protected void delete(object sender, GridViewDeleteEventArgs e)
    {
   
        int regid = Convert.ToInt32(dg.DataKeys[e.RowIndex].Value);
        adv.deleterecord(regid);
        dg.EditIndex = -1;
      this.DataBind1();
    }
    protected void DataBind1()
    {
         DataSet ds = new DataSet();
      
        SqlDataAdapter myAdapter = new SqlDataAdapter("collegepathupdate", adv.connect());
       
        myAdapter.Fill(ds);
        PagedDataSource objPds = new PagedDataSource();
        objPds.DataSource = ds.Tables[0].DefaultView;

        objPds.AllowPaging = true;
        objPds.PageSize = 13;

        objPds.CurrentPageIndex = CurrentPage;

        lblfind.Text = "Page: " + (CurrentPage + 1).ToString() + " of "
            + objPds.PageCount.ToString() + "    Total Records :(" + ds.Tables[0].Rows.Count.ToString() + ")";

        // Disable Prev or Next buttons if necessary
        cmdPrev.Enabled = !objPds.IsFirstPage;
        cmdNext.Enabled = !objPds.IsLastPage;
        dg.DataSource = objPds;
        dg.DataBind();

    }

    protected void cmdPrev_Click(object sender, System.EventArgs e)
    {
        // Set viewstate variable to the previous page
        CurrentPage -= 1;

        // Reload control
        DataBind1();
    }

    protected void cmdNext_Click(object sender, System.EventArgs e)
    {
        // Set viewstate variable to the next page
        CurrentPage += 1;

        // Reload control
        DataBind1();
    }
    public int CurrentPage
    {
        get
        {
            // look for current page in ViewState
            object o = this.ViewState["_CurrentPage"];
            if (o == null)
                return 0; // default to showing the first page
            else
                return (int)o;
        }

        set
        {
            this.ViewState["_CurrentPage"] = value;
        }
    }
   
}

public class advReport
{
   public advReport()
    {
    }

 public void updateevents(string regid,string name)
    {
        int chk=1;
      
        SqlCommand cmd = new SqlCommand("insert into collegepath(regid,collegeurl,updatechk) values(@regid,@name,@chk)", connect());
        cmd.Parameters.Add("@regid", SqlDbType.Int).Value = Convert.ToInt32(regid);
        cmd.Parameters.Add("@name", SqlDbType.NVarChar).Value = name;
        cmd.Parameters.Add("@chk", SqlDbType.Int).Value = chk;

       
        cmd.ExecuteNonQuery();
        cmd.Connection.Close();
    }
public void deleterecord(int regid)
    {
        SqlCommand cmd = new SqlCommand("delete from registration where regID=@regid", connect());
        cmd.Parameters.Add("@regid", SqlDbType.Int).Value = regid;
        cmd.ExecuteNonQuery();
        cmd.Connection.Close();

    }
}

5 comments :

  1. 1mThank's.2k I compleatly agree with last post. usr
    купить ламинат 9a

    ReplyDelete
  2. 7iThank's.4y I compleatly disagree with last post . zoa
    ламинат и паркет 9i

    ReplyDelete
  3. Invitation to new programming Resources Website



    Dear Sir,

    I hope you are doing well. I got this email address from one of your contribution web site. I have launched a web site www.codegain.com and it is basically aimed C#,JAVA,VB.NET,ASP.NET,AJAX,Sql Server,Oracle,WPF,WCF and etc resources, programming help, articles, code snippet, video demonstrations and problems solving support. I would like to invite you as an author and a supporter.
    Looking forward to hearing from you and hope you will join with us soon.

    Thank you
    RRaveen
    Founder CodeGain.com

    ReplyDelete
  4. Hi there, I found your web site via Google while looking for a related topic, your web site got here up, it appears to be like great. I have bookmarked to my favourites|added to my bookmarks.

    ReplyDelete

AJAX, asp, Asp.net, asp.net and sql server security, Asp.net IntemIndex, C#, Css, DataBinder.Eval, DataKeyNames, Datalist, Datapager, DataSet, DataTable, DropDownList, FindControl, gridview, JavaScript, jquery, Listview, Paging, Regex, RegularExpression, Repeater, Server side validation, Sql Server, timer, timercallback, Validation, XML, xmlnode, XPath