<asp:TemplateField HeaderText="Edit">
<ItemTemplate><asp:HiddenField ID="hdnedit" runat="server" Value='<%# Bind("ID") %>' /><asp:ImageButton ID="imgbtnedit" runat="server" CommandName="Edit" ToolTip="Edit"ImageUrl="/_Layouts/edit.png" /></ItemTemplate><HeaderStyle HorizontalAlign="Center" /><ItemStyle HorizontalAlign="Center" /></asp:TemplateField><asp:TemplateField HeaderText="Delete"><ItemTemplate><asp:HiddenField ID="hdndelete" runat="server" Value='<%# Bind("ID") %>' /><asp:ImageButton ID="imgbtndelete" runat="server" CommandName="Delete" ToolTip="Delete"ImageUrl="/_Layouts/delete.png" OnClientClick="Javascript:return fnDelete(this);" /></ItemTemplate></asp:TemplateField>--------------------------------------void gvform_RowEditing(object sender, GridViewEditEventArgs e){
GridViewRow gvedit = gvform.Rows[e.NewEditIndex];
Label lblidval = (Label)gvedit.FindControl("lblid");lblidvalue.Text = lblidval.Text;
try{
using (SPSite osite = new SPSite(SPContext.Current.Site.ID)){
using (SPWeb oweb = osite.OpenWeb()){
SPList olist = oweb.Lists.TryGetList("EmployeeList");
if (olist != null){
SPListItem splitem = olist.Items.GetItemById(Convert.ToInt32(lblidval.Text));txtFName.Text =
Convert.ToString(splitem["FName"]);txtLName.Text =
Convert.ToString(splitem["LName"]);txtEmpID.Text =
Convert.ToString(splitem["EmpID"]);txtEmail.Text =
Convert.ToString(splitem["MailID"]);ddjoindate.SelectedDate =
Convert.ToDateTime(splitem["JoinDate"]);dddob.SelectedDate =
Convert.ToDateTime(splitem["DOB"]);dddepartment.SelectedIndex =
Convert.ToInt32(splitem["Dept"]); // dropdown Bind_Data();
}
-----------------------
DELETING
(Get ID from gridview)
void gvform_RowDeleting(object sender, GridViewDeleteEventArgs e){
try{
GridViewRow gvrow = gvform.Rows[e.RowIndex];
Label lblid = (Label)gvrow.FindControl("lblid");
int deleteval = Convert.ToInt32(lblid.Text);Deleted_Action_Details(deleteval);
}
catch (Exception ex){
throw ex;}
}
---------
(Assign the ID)
void Deleted_Action_Details(int val){
try{
using (SPSite osite = new SPSite(SPContext.Current.Site.ID)){
using (SPWeb oweb = osite.OpenWeb()){
SPList olist = oweb.Lists.TryGetList("EmployeeList");
if (olist != null){
SPListItem splitem = olist.Items.GetItemById(val);oweb.AllowUnsafeUpdates =
true;splitem.Delete();
oweb.AllowUnsafeUpdates =
false;Bind_Data();
}
}
}
Bind_Data();
}
catch (Exception ex){
throw ex;}
}
No comments:
Post a Comment