Hi All
Please help me in this.
From 1 form i am saving data to list and displaying list items in grid.
Edit/Delete options in grid..(data should not be edited in grid).
Data will display in form....from grid(i.e splist data).I need to edit that data and update.
If i update that should update the existing splist item and display in grid.
Same for the delete.
Please check the code what i have wrote.
Edit/Delete is not working...(instead of updating the esisting item,it is adding as new item)
protected void gvConslt_RowEditing(object sender, GridViewEditEventArgs e){
try
{
BtnConsultant.Text = "Update";
//objDALProjectCenter = new DALProjectCenter();
// HdnConslt.Value = gvConslt.DataKeys[e.NewEditIndex].Value.ToString();
txtSpec.Text = (gvConslt.Rows[e.NewEditIndex].FindControl("lblSpecl") as Label).Text;
ddlGCPn.SelectedItem.Text=(gvConslt.Rows[e.NewEditIndex].FindControl("lblProjectName") as Label).Text;
txtName.Text = (gvConslt.Rows[e.NewEditIndex].FindControl("lblNAME") as Label).Text;
txtAppt.Text = (gvConslt.Rows[e.NewEditIndex].FindControl("lblAPPOINTED") as Label).Text;
//objDALProjectCenter.IUD_Conslt(objDALProjectCenter);
BindGrid();
}
catch (Exception ex)
{
throw ex;
}
}
protected void gvConslt_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
try
{
objDALProjectCenter = new DALProjectCenter();
BtnConsultant.Text = "Delete";
}
BindGrid();
}
catch (Exception ex)
{
throw ex;
}
}
protected void FillDd()
{
try
{
objDALProjectCenter = new DALProjectCenter();
dsConsultant = objDALProjectCenter.GetConsultantFromUID();
ddlGCPn.DataSource = dsConsultant;
ddlGCPn.DataBind();
ddlGCPn.Visible = true;
ddlGCPn.DataValueField = "ProjectUID"; // List field holding value
ddlGCPn.DataTextField = "ProjectName"; // List field holding name
ddlGCPn.DataBind();
}
catch (Exception ex)
{
LoggingService.ShowMessage(LoggingService.ErrorType.Error, LoggingService.ErrorMsgSize.Size25, ex.Message, ltrErrorMsg);
}
}
protected void BtnConsultant_Click(object sender, EventArgs e)
{
try
{
using (SPSite site = new SPSite(SPContext.Current.Web.Url.ToString()))
{
using (SPWeb web = site.OpenWeb())
{
//ltrErrorMsg.Visible = false;
SPWeb objSPWeb = SPControl.GetContextWeb(System.Web.HttpContext.Current);
SPUser objSPUser = objSPWeb.CurrentUser;
SPUser currentuser = SPContext.Current.Web.CurrentUser;
if (BtnConsultant.Text == "Submit")
{
SPList list = web.Lists["LST.Consultants"];
SPListItem lst = list.Items.Add();
lst["ProjectName"] = ddlGCPn.SelectedItem.Text;
lst["SPECIALITY"] = txtSpec.Text;
lst["NAME"] = txtName.Text;
lst["APPOINTED"] = txtAppt.Text;
lst.Update();
list.Update();
BindGrid();
LoggingService.ShowMessage(LoggingService.ErrorType.Success, LoggingService.ErrorMsgSize.Size25, "Consultant added Successfully..", ltrErrorMsg);
}
else if (BtnConsultant.Text == "Update")
{
SPList list = web.Lists["LST.Consultants"];
SPListItem lst = list.Items.Add();
lst["ProjectName"] = ddlGCPn.SelectedItem.Text;
lst["SPECIALITY"] = txtSpec.Text;
lst["NAME"] = txtName.Text;
lst["APPOINTED"] = txtAppt.Text;
lst.Update();
list.Update();
Guid itemId = lst.UniqueId;
SPListItem itemUpdate = web.Lists["LST.Consultants"].Items[itemId];
BindGrid();
LoggingService.ShowMessage(LoggingService.ErrorType.Success, LoggingService.ErrorMsgSize.Size25, "Consultant updated Successfully..", ltrErrorMsg);
}
else if (BtnConsultant.Text == "Delete")
{
SPList list = web.Lists["LST.Consultants"];
SPListItem lst = list.Items.Add();
Guid itemId = lst.UniqueId;
SPListItem itemToDelete = list.Items[itemId];
itemToDelete.Delete();
BindGrid();
LoggingService.ShowMessage(LoggingService.ErrorType.Success, LoggingService.ErrorMsgSize.Size25, "Consultant deleted Successfully..", ltrErrorMsg);
}
else
{
LoggingService.ShowMessage(LoggingService.ErrorType.Success, LoggingService.ErrorMsgSize.Size25, "Operation failed..", ltrErrorMsg);
}
ddlGCPn.ClearSelection();
txtSpec.Text = string.Empty;
txtName.Text = string.Empty;
txtAppt.Text = string.Empty;
}
}
}
catch (Exception ex)
{
LoggingService.ShowMessage(LoggingService.ErrorType.Error, LoggingService.ErrorMsgSize.Size25, ex.Message, ltrErrorMsg);
}
}
Please help me ASAP.Pleaseeeee
Thanks in advance
Sowjanya G