Hitesh Dabhi

Hitesh Dabhi

  • NA
  • 4
  • 7.3k

ASP.net Gridview in the Not updated value

Dec 14 2013 1:27 AM
Hello 

I have one website development in back end  work in the one client grid view option than one command field edit update and cancel.
But in the page in the update not value. so behind in the error of the page 

Error
Line 62:     protected void gvClientDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
Line 63:     {
Line 64:         int clientid = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());
Line 65:         GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex]; 
Line 66: Label lblID = (Label)row.FindControl("lblID");  


and my behind code see now.
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class all_user_deatils : System.Web.UI.Page
{
    SqlConnection conn;
    protected void Page_Load(object sender, EventArgs e)
    {
        conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\HPB Industreis PvtLtd\\App_Data\\HPBData.mdf;Integrated Security=True;User Instance=True");
        
        if (!IsPostBack)
        {
            gvbind();
        }
    }
    protected void gvbind()
    {
        conn.Open();
        SqlCommand cmd = new SqlCommand("Select * from Planform_Client", conn);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        conn.Close();
        if (ds.Tables[0].Rows.Count > 0)
        {
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }
        else
        {
            ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
            GridView1.DataSource = ds;
            GridView1.DataBind();
            int columncount = GridView1.Rows[0].Cells.Count;
            GridView1.Rows[0].Cells.Clear();
            GridView1.Rows[0].Cells.Add(new TableCell());
            GridView1.Rows[0].Cells[0].ColumnSpan = columncount;
            GridView1.Rows[0].Cells[0].Text = "No Records Found";
        }
    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
         
    }

    protected void gvClientDetails_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        gvbind();
    }
    protected void gvClientDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int clientid = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());
        GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
        Label lblID = (Label)row.FindControl("lblID");
        //TextBox txtname=(TextBox)gr.cell[].control[];
        TextBox firstname = (TextBox)row.Cells[0].Controls[0];
        TextBox middlename = (TextBox)row.Cells[1].Controls[0];
        TextBox lastname = (TextBox)row.Cells[2].Controls[0];
        TextBox address = (TextBox)row.Cells[3].Controls[0];
        TextBox gender = (TextBox)row.Cells[4].Controls[0];
        TextBox day = (TextBox)row.Cells[5].Controls[0];
        TextBox month= (TextBox)row.Cells[6].Controls[0];
        TextBox year = (TextBox)row.Cells[7].Controls[0];
        TextBox mobileno = (TextBox)row.Cells[8].Controls[0];
        TextBox emailid = (TextBox)row.Cells[9].Controls[0];
        TextBox city = (TextBox)row.Cells[10].Controls[0];
        TextBox pincode = (TextBox)row.Cells[11].Controls[0];
        TextBox state = (TextBox)row.Cells[12].Controls[0];
        TextBox country = (TextBox)row.Cells[13].Controls[0];
        TextBox images = (TextBox)row.Cells[14].Controls[0];
        TextBox planname = (TextBox)row.Cells[15].Controls[0];
        TextBox timeperiod = (TextBox)row.Cells[16].Controls[0];
        TextBox amount = (TextBox)row.Cells[17].Controls[0];
        TextBox joindate = (TextBox)row.Cells[18].Controls[0];
        TextBox cycleperiod = (TextBox)row.Cells[19].Controls[0];
        TextBox paydetails = (TextBox)row.Cells[20].Controls[0];
        TextBox accountholder = (TextBox)row.Cells[21].Controls[0];
        TextBox bankname = (TextBox)row.Cells[22].Controls[0];
        TextBox accountnumber = (TextBox)row.Cells[23].Controls[0];
        TextBox bankbranch = (TextBox)row.Cells[24].Controls[0];
        TextBox ifcscode = (TextBox)row.Cells[25].Controls[0];
        TextBox standermember = (TextBox)row.Cells[26].Controls[0];
        TextBox standernumber = (TextBox)row.Cells[27].Controls[0];
        TextBox uniqid = (TextBox)row.Cells[28].Controls[0];
       
        


        //TextBox textadd = (TextBox)row.FindControl("txtadd");
        //TextBox textc = (TextBox)row.FindControl("txtc");
        GridView1.EditIndex = -1;
        conn.Open();
        //SqlCommand cmd = new SqlCommand("SELECT * FROM detail", conn);
        SqlCommand cmd = new SqlCommand("update Planform_Client set firstname='" + firstname.Text + "',middlename='" + middlename.Text + "',lastname='" + lastname.Text + "',address='" + address.Text + "',gender='" + gender.Text + "',day='" + day.Text + "',year='" + year.Text + "', mobileno='" + mobileno.Text + "',emailid='" + emailid.Text + "',city='" + city.Text + "',pincode='" + pincode.Text + "',state='" + state.Text + "',country='" + country.Text + "',images='" + images.Text + "',planname='" + planname.Text + "',timeperiode='" + timeperiod.Text + "',amount='" + amount.Text + "',joindate='" + joindate.Text + "',cycleperiod='" + cycleperiod.Text + "', paydetails='" + paydetails.Text + "',accountholder='" + accountholder.Text + "',bankname='" + bankname.Text + "',accountnumber='" + accountnumber.Text + "',bankbranch='" + bankbranch.Text + "',ifcscode='" + ifcscode.Text + "',standermember='" + standermember.Text + "', standernumber='" + standernumber.Text + "',uniqid='" + uniqid.Text + "' where clientid='" + clientid + "'", conn);
        cmd.ExecuteNonQuery();
        conn.Close();
        gvbind();
        //GridView1.DataBind();
    }
    protected void gvClientDetails_RowCanclingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        gvbind();
    }
    protected void gvClientDetails_RowCommand(object sender, GridViewCommandEventArgs e)
    {
       
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        gvbind();

    }
}
 

So Plz My help me and let me know.

Regards,
Hitesh Dabhi

Answers (3)