protected void gvclass_RowUpdating1(object sender, GridViewUpdateEventArgs e)
{
classinfo infoclass = new classinfo();
classsp spclass = new classsp();
GridViewRow row = gvclass.Rows[e.RowIndex];
infoclass.classId = decimal.Parse(gvclass.DataKeys[e.RowIndex].Value.ToString());
infoclass.className = ((TextBox)row.FindControl("txtclassname")).Text;
infoclass.noOfSeats = int.Parse(((TextBox)row.FindControl("txtno")).Text);
int a = spclass.ClassEdit(infoclass);
gvclass.EditIndex = -1;
gridfill();
}
after clicking editt
gettin' error
Sanjeeb LenkaPosted Aug 24, 2013, 7:18 AM
DataSourceID="SqlDataSource1" BackColor="White" BorderColor="#E7E7FF"
BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal"
onpageindexchanging="gvclass_PageIndexChanging1"
onrowcancelingedit="gvclass_RowCancelingEdit1"
onrowediting="gvclass_RowEditing1" onrowupdating="gvclass_RowUpdating1"
onselectedindexchanging="gvclass_SelectedIndexChanging1"
onsorting="gvclass_Sorting">
Safeer SafeerPosted Aug 24, 2013, 7:15 AM
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.Drawing;
namespace ERP
{
public partial class _class : System.Web.UI.Page
{
public void clear()
{
txtclass.Text = "";
txtno.Text = "";
}
public void view1(decimal cid)
{
classinfo infoclass = new classinfo();
classsp spclass = new classsp();
infoclass = spclass.ClassViews(cid);
txtclassname.Text = infoclass.className;
txtno.Text = infoclass.noOfSeats.ToString();
mvclass.SetActiveView(vclass);
}
public void gridfill()
{
classsp spclass = new classsp();
DataTable dt = new DataTable();
dt = spclass.ClassViewall();
//gvclass.DataSource = dt;
gvclass.DataBind();
}
public void save()
{
lblmsg.Text = "";
classinfo infoclass = new classinfo();
classsp spclass = new classsp();
infoclass.className = txtclass.Text;
infoclass.noOfSeats = int.Parse(txtno.Text.ToString());
if (ViewState["classID"] == null)
{
int a = spclass.classAdd(infoclass);
if (a >= 0)
{
lblmsg.Text = "Saved Success";
lblmsg.ForeColor = Color.Green;
gridfill();
clear();
}
else
{
lblmsg.Text = "Already Exist";
lblmsg.ForeColor = Color.Red;
}
}
else
{
infoclass.classId = decimal.Parse(ViewState["classID"].ToString());
int b = spclass.ClassEdit(infoclass);
ViewState["classID"] = null;
if (b >= 0)
{
lblmsg.Text = "Updated";
lblmsg.ForeColor = Color.Green;
gridfill();
clear();
}
else
{
lblmsg.Text = "already exist";
lblmsg.ForeColor = Color.Red;
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
gridfill();
if (gvclass.Rows.Count > 0)
{
lblclass.Visible = false;
txtclass.Visible = false;
mvclass.SetActiveView(vclassgrid);
}
else
{
mvclass.SetActiveView(vclass);
}
}
}
protected void btnsave_Click(object sender, EventArgs e)
{
save();
}
protected void btnclear_Click(object sender, EventArgs e)
{
clear();
lblmsg.Text = "";
}
protected void txtclass_TextChanged(object sender, EventArgs e)
{
classsp spclass = new classsp();
if (txtclass.Text != string.Empty)
{
gvclass.DataSource = spclass.ClassGridSearch(txtclass.Text.Trim());
gvclass.DataBind();
}
else
{
spclass.ClassViewall();
gvclass.DataBind();
}
}
protected void gvclass_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvclass.PageIndex = e.NewPageIndex;
gridfill();
}
protected void gvclass_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
ViewState["classID"] = decimal.Parse(gvclass.DataKeys[e.NewSelectedIndex]["classId"].ToString());
decimal d = decimal.Parse(ViewState["classID"].ToString());
view1(d);
}
protected void gvclass_RowEditing(object sender, GridViewEditEventArgs e)
{
gvclass.EditIndex = e.NewEditIndex;
gridfill();
}
protected void gvclass_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
e.Cancel = true;
gvclass.EditIndex = -1;
gridfill();
}
protected void gvclass_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
classinfo infoclass = new classinfo();
classsp spclass = new classsp();
GridViewRow row = gvclass.Rows[e.RowIndex];
infoclass.classId = decimal.Parse(gvclass.DataKeys[e.RowIndex].Value.ToString());
infoclass.className = ((TextBox)row.FindControl("txtclassname")).Text;
infoclass.noOfSeats = int.Parse(((TextBox)row.FindControl("txtno")).Text);
int a = spclass.ClassEdit(infoclass);
gvclass.EditIndex = -1;
gridfill();
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
lblmsg.Text = "";
mvclass.SetActiveView(vclass);
}
protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
{
lblmsg.Text = "";
classsp spclass = new classsp();
int a = spclass.ClassDelete(decimal.Parse(ViewState["classID"].ToString()));
ViewState["classID"] = null;
if (a >= 0)
{
lblmsg.Text = "deleted successfully";
gridfill();
ImageButton1.Enabled = false;
clear();
}
else
{
lblmsg.Text = "can't delete";
ImageButton1.Enabled = false;
}
}
protected void gvclass_PageIndexChanging1(object sender, GridViewPageEventArgs e)
{
gvclass.PageIndex = e.NewPageIndex;
gridfill();
}
protected void gvclass_SelectedIndexChanging1(object sender, GridViewSelectEventArgs e)
{
ViewState["classID"] = decimal.Parse(gvclass.DataKeys[e.NewSelectedIndex]["classId"].ToString());
decimal d = decimal.Parse(ViewState["classID"].ToString());
view1(d);
}
protected void gvclass_Sorting(object sender, GridViewSortEventArgs e)
{
classsp spclass = new classsp();
DataTable dt = new DataTable();
dt = spclass.ClassViewall();
if (ViewState["sort"] == null)
{
dt.DefaultView.Sort = e.SortDirection + "DESC";
gvclass.DataSource = dt;
gvclass.DataBind();
ViewState["sort"] = "DESC";
}
else
{
dt.DefaultView.Sort = e.SortExpression + "ASC";
gvclass.DataSource = dt;
gvclass.DataBind();
ViewState["sort"] = null;
}
}
protected void gvclass_RowEditing1(object sender, GridViewEditEventArgs e)
{
gvclass.EditIndex = e.NewEditIndex;
gridfill();
}
protected void gvclass_RowCancelingEdit1(object sender, GridViewCancelEditEventArgs e)
{
e.Cancel = true;
gvclass.EditIndex = -1;
gridfill();
}
protected void gvclass_RowUpdating1(object sender, GridViewUpdateEventArgs e)
{
classinfo infoclass = new classinfo();
classsp spclass = new classsp();
GridViewRow row = gvclass.Rows[e.RowIndex];
infoclass.classId = decimal.Parse(gvclass.DataKeys[e.RowIndex].Value.ToString());
infoclass.className = ((TextBox)row.FindControl("txtICLassName")).Text;
infoclass.noOfSeats = int.Parse(((TextBox)row.FindControl("txtISeats")).Text);
int a = spclass.ClassEdit(infoclass);
gvclass.EditIndex = -1;
gridfill();
}
}
}
Safeer SafeerPosted Aug 24, 2013, 7:13 AM
Sanjeeb LenkaPosted Aug 24, 2013, 7:08 AM
infoclass.classId=decimal.Parse(gvclass.DataKeys[e.RowIndex].Value[classid].ToString());
and check what the value you are getting in the highlighted line
RiniPosted Aug 24, 2013, 6:53 AM
Safeer SafeerPosted Aug 24, 2013, 6:51 AM
Sanjeeb LenkaPosted Aug 24, 2013, 6:47 AM
Safeer SafeerPosted Aug 24, 2013, 6:40 AM
Sanjeeb LenkaPosted Aug 24, 2013, 5:28 AM
try this code in row updating
classinfo infoclass = new classinfo();
classsp spclass = new classsp();
GridViewRow row=gvclass.Rows.[e.RowIndex];
infoclass.classId=decimal.Parse(gvclass.DataKeys[e.RowIndex].Value.ToString());
infoclass.className=((TextBox)row.FindControl("txtICLassName")).Text;
infoclass.noOfSeats=int.Parse(((TextBox)row.FindControl("txtISeats")).Text);
int a=spclass.ClassEdit(infoclass);
gvclass.EditIndex = -1;
gridfill();
Safeer SafeerPosted Aug 24, 2013, 5:11 AM
BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal"
onpageindexchanging="gvclass_PageIndexChanging1"
onrowcancelingedit="gvclass_RowCancelingEdit1"
onrowediting="gvclass_RowEditing1" onrowupdating="gvclass_RowUpdating1"
onselectedindexchanging="gvclass_SelectedIndexChanging1"
onsorting="gvclass_Sorting">
Sanjeeb LenkaPosted Aug 24, 2013, 5:00 AM