AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 how to write edit update in grid view using session
Posted by Rajeswari.P on  5/30/2013 5:21:48 AM Category: C#
Add to my favorites
Email to friend
sql 2008r2. running platform:c# 2008 4.0..
This is creation page:

protected void Page_Load(object sender, EventArgs e)
{
try
{
DbObj1 = new PF();
if (IsPostBack == false)
{
if (Session == null)
{
Response.Redirect("Session.aspx", false);

}
else
{


if (Session != null)
{

Session["Eve"] = Txtcd.Text; //create session

Txtcd.Text = Session["Eve"].ToString();
Session["TxtUpd"] = Txtcd.Text;
Session["TxtUpd"] = TxtIdpfno.Text;
Session["Updation"] = Eve1;

//Txtcd.Text = Session["TxtUpd"].ToString();
//TxtIdpfno.Text = Session["Eve"].ToString();


if (Session["Eve"].ToString() != null)
{
Eve1 = Session["Eve"].ToString();
Eve1 = Session["Updation"].ToString();

}


//svc1 = Session["Event"].ToString();


//List<string> values = new List<string>();
//if (Session["Eve"] != null)

//values = (List<string>)Session["Eve"];
//foreach (string str in values)
//{
//Response.Redirect("value:" + str + "<br>");
//values.Add("new click");
//Session["Eve"] = values;

//}
//}
//}
//}
//if (Session["Event"].ToString() != null)
//{
//svc1 = Session["Event"].ToString();
//}
//Code = Session["TxtUpd"].ToString();

//Code = Session["Event"].ToString();
//Txtcd.Text = Session["Code"].ToString();
//svc1 = Session["Event"].ToString();




//svc1 = Session["Event"].ToString();


//Code = Session["TxtUpd"].ToString();

if (Eve1 == "Updation")
{

lblhead.Text = "STAYING PERSON DETAILS";
BtnAdd.Text = "Updation";
Code = Session["TxtUpd"].ToString();
Ds = new DataSet();
Ds = DbObj1.Details_StayingRoom(Code);
foreach (DataRow Dr in Ds.Tables[0].Rows)
{

Txtcd.Text = Dr["Code"].ToString();
Txthstlcode.Text = Dr["HostelCode"].ToString();
TxtRmno.Text = Dr["RoomNo"].ToString();
Txtpername.Text = Dr["PersonName"].ToString();
Txtdsgnation.Text = Dr["Designation"].ToString();
Txtadrs.Text = Dr["Address"].ToString();
TxtIdpf.Text = Dr["IdProof"].ToString();
TxtIdpfno.Text = Dr["IdProofNo"].ToString();
Txtjdate.Text = Dr["JoinDate"].ToString();
Txtrmrent.Text = Dr["RoomRent"].ToString();
Txtrmadvance.Text = Dr["RoomAdvance"].ToString();
TxtNofmonth.Text = Dr["NoOfMonth"].ToString();
Txtpaymentdate.Text = Dr["PaymentDate"].ToString();
Txtcurrentmonthrent.Text =Dr["CurrentMonthRent"].ToString();
String RbnHostelType = Dr["HostelType"].ToString();
String RbnRoomType = Dr["RoomType"].ToString();
String RbnNoOfSharing = Dr["NoOfSharing"].ToString();

if (RbnHostelType == "Girls")
{
RbnGirls.Checked = true;
}
else
{
RbnBoys.Checked = true;
}
if (RbnRoomType == "Ac")
{
RbnAc.Checked = true;
}
else
{
RbnNonAc.Checked = true;
}
if (RbnNoOfSharing == "IV")
{
RbnIV.Checked = true;
}
else if (RbnNoOfSharing == "III")
{
RbnIII.Checked = true;
}
else if (RbnNoOfSharing == "II")
{
RbnII.Checked = true;
}
else
{

RbnI.Checked = true;

}

}
}
}


}
}
}
catch (Exception ex)
{

}

}


//else
//{
// AutoNumber();

//}




protected void BtnAdd_Click(object sender, EventArgs e)
{
DbObj1 = new PF();
String HostelType = "";
String RoomType = "";
String NoOfSharing = "";

try
{
if (RbnGirls.Checked == true)
{
HostelType = "Girls";
}
else
{
HostelType = "Boys";
}
if (RbnAc.Checked == true)
{
RoomType = "Ac";
}
else
{
RoomType = "Non-Ac";
}
if (RbnIV.Checked == true)
{
NoOfSharing = "IV";
}
else if (RbnIII.Checked == true)
{
NoOfSharing = "III";
}
else if (RbnII.Checked == true)
{
NoOfSharing = "II";
}
else
{
NoOfSharing = "I";
}

// if (Session["TxtUpd"].ToString() == "")
//{
// AutoNumber();
//}
if (!DbObj1.Checkstay(Txtcd.Text, Session["TxtUpd"].ToString()))
{

if (!DbObj1.Checkstay1(TxtIdpfno.Text, Session["TxtUpd"].ToString()))
{
if (DbObj1.insstayingdtls(Txtcd.Text, Txthstlcode.Text, HostelType, TxtRmno.Text, RoomType, NoOfSharing, Txtpername.Text, Txtdsgnation.Text, Txtadrs.Text, TxtIdpf.Text, TxtIdpfno.Text, Txtjdate.Text, Txtrmrent.Text, Txtrmadvance.Text, TxtNofmonth.Text, Txtpaymentdate.Text, Txtcurrentmonthrent.Text))
{

if (Session["Eve"].ToString() == "Updation")
{

String cstext = "alert('Data Successfully Updated');windows.location='StayingPers.aspx';";
Page.ClientScript.RegisterStartupScript(this.GetType(), "PopupScript", cstext, true);
}

else
{
String cstext = "alert('Data Successfully Created');windows.location='StayingPers.aspx'";
Page.ClientScript.RegisterStartupScript(this.GetType(), "PopupScript", cstext, true);
// Response.Redirect("session.aspx");

}

}
else
{
String cstext = "alert('Invalid Details');";
Page.ClientScript.RegisterStartupScript(this.GetType(), "PopupScript", cstext, true);

}

}
else
{
String cstext = "alert('This IdProofNo Already exists');";
Page.ClientScript.RegisterStartupScript(this.GetType(), "PopupScript", cstext, true);
}
}

else
{
String cstext = "alert('This code Already exists');";
Page.ClientScript.RegisterStartupScript(this.GetType(), "PopupScript", cstext, true);
}

}

catch (Exception ex)
{
//message box(ex.ToString);
String cstext = "alert('There is some error occured');";
Page.ClientScript.RegisterStartupScript(this.GetType(), "PopupScript", cstext, true);
}

}
protected void AutoNumber()
{
Cnt = 0;
Ds = new DataSet();
Ds = DbObj1.AutoNumSlsRep("AMRMD");
foreach (DataRow Dr in Ds.Tables[0].Rows)
{
if (Dr["Id"].ToString() == "")
{
Cnt = Cnt + 1;
}
else
{
int Id = Convert.ToInt16(Dr["ID"].ToString());
Cnt = Id + 1;
}
}

}
}

this is update page:this redirect to previous codiing page..Plz help me

protected void Page_Load(object sender, EventArgs e)
{
try
{
DbObj1 = new PF();
if (IsPostBack == false)
{
Ds = new DataSet();
Ds = DbObj1.Details_StayingRoom("");
GridView1.DataSource = Ds.Tables[0];
GridView1.DataBind();

}
}
catch (Exception ex)
{
}
}



protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
if (e.CommandName == "Update1")
{
int x = GridView1.Rows.Count;
int index = Convert.ToInt32(e.CommandArgument.ToString());
Session["Eve1"] = "Updation";
Session["TxtUpd"] = GridView1.Rows[index].Cells[0];
Response.Redirect("StayingPers.aspx", false);
}
}

catch (Exception ex)
{
}
}
protected void lblNew_Click(object sender, EventArgs e)
{

Session["Event"] = "CREATION";
Response.Redirect("Stayingpers.aspx");
}


}


Post Your Reply Post New Question

 Viewer's Reply
GridView Edit and Update
Answered By Moderator1 on 6/28/2013 9:09:22 PM
Hi,

Kindly refer our article at the below link

http://www.aspdotnetcodes.com/GridView_Insert_Edit_Update_Delete.aspx
 
Post Your Reply If you still have problem, post it again under this reply for better response.

 
Sponsored by
No Nonsense XML Web Development With PHP - Free 146 Page Preview!
Speech Technology Magazine
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!