Dhimesh Parmar

Dhimesh Parmar

  • NA
  • 126
  • 14.5k

i can'n perform edit and delete operation?

Feb 28 2018 3:09 AM
code like this
  1. using System;  
  2. using System.Web.UI.HtmlControls;  
  3. using System.Collections.Generic;  
  4. using System.Linq;  
  5. using System.Web;  
  6. using System.Web.UI;  
  7. using System.Web.UI.WebControls;  
  8. using GridFun.BE;  
  9. using GridFun.DAL;  
  10. using GridFun.Common;  
  11. using System.Data.SqlClient;  
  12. using System.Data;  
  13.   
  14. public partial class Student : System.Web.UI.Page  
  15. {  
  16.       
  17.     studentDAL dal = new studentDAL();  
  18.     studentBE bal= new studentBE();  
  19.     
  20.     protected void Page_Load(object sender, EventArgs e)  
  21.     {  
  22.     
  23.         if (!IsPostBack)  
  24.         {  
  25.             //bal = new studentBE();  
  26.             //dal = new studentDAL();  
  27.             //gridStud.DataSource = dal.getdata();  
  28.             //gridStud.DataBind();  
  29.             binddata();  
  30.         }  
  31.     }  
  32.   
  33.     public void binddata()  
  34.     {  
  35.         gridStud.DataSource = dal.getdata();  
  36.         gridStud.DataBind();  
  37.     }  
  38.   
  39.     protected void BtnAdd_Click(object sender, EventArgs e)  
  40.     {  
  41.         dal = new studentDAL();  
  42.         bal = new studentBE();  
  43.         bal.name = txtStudentName.Text;  
  44.         if (RadioButton1.Checked)  
  45.         {  
  46.             bal.gender = "Male";  
  47.         }  
  48.         else  
  49.         {  
  50.             bal.gender = "Female";  
  51.         }  
  52.         bal.brithDate = Convert.ToDateTime(TextCalendar.Text);  
  53.         bal.emailid = txtEmail.Text;  
  54.         bal.mobilenumber = txtMobile.Text;  
  55.         bal.status = 1;  
  56.         bal.createdOn = DateTime.Now;  
  57.         bal.modifiedOn = DateTime.Now;  
  58.         dal.addStudent(bal);  
  59.         Response.Redirect("Student.aspx");  
  60.     }  
  61.   
  62.   
  63.     protected void gridStud_RowUpdating(object sender, GridViewUpdateEventArgs e)  
  64.     {  
  65.         LinkButton btn = (LinkButton)gridStud.Rows[e.RowIndex].FindControl("linkUpdate");  
  66.   
  67.         if (btn.CommandName == "UPDATE")  
  68.         {  
  69.             int studentId = Convert.ToInt32(gridStud.DataKeys[e.RowIndex].Value.ToString());  
  70.   
  71.             TextBox txtStudName = (TextBox)gridStud.Rows[e.RowIndex].FindControl("txtStud");  
  72.             RadioButton rd1 = (RadioButton)gridStud.Rows[e.RowIndex].FindControl("RadioButton3");  
  73.             RadioButton rd2 = (RadioButton)gridStud.Rows[e.RowIndex].FindControl("RadioButton4");  
  74.              
  75.             TextBox txtBirthdate = (TextBox)gridStud.Rows[e.RowIndex].FindControl("txtDate");  
  76.             TextBox txtEmail = (TextBox)gridStud.Rows[e.RowIndex].FindControl("txtEmail");  
  77.             TextBox txtMobile = (TextBox)gridStud.Rows[e.RowIndex].FindControl("txtmob");  
  78.             
  79.             
  80.   
  81.                
  82.                     studentCommon c = new studentCommon();  
  83.                     SqlCommand cmd = new SqlCommand("studIUD");  
  84.                     cmd.CommandType = CommandType.StoredProcedure;  
  85.   
  86.                     cmd.Parameters.AddWithValue("StatementType""UPDATE");  
  87.               
  88.                     // cmd.Parameters.AddWithValue("studentId", studentId);  
  89.   
  90.                     cmd.Parameters.AddWithValue("name", txtStudName);  
  91.   
  92.                     if (rd1.Checked)  
  93.                     {  
  94.                         cmd.Parameters.AddWithValue("gender""Male");  
  95.                     }  
  96.                     else {  
  97.                         cmd.Parameters.AddWithValue("gender""Female");  
  98.                     }  
  99.   
  100.                       
  101.   
  102.   
  103.                     cmd.Parameters.AddWithValue("brithDate", txtBirthdate);  
  104.                     cmd.Parameters.AddWithValue("emailid", txtEmail);  
  105.                     cmd.Parameters.AddWithValue("mobilenumber", txtMobile);  
  106.                       
  107.                     c.ExecuteNonQueryByCommand(cmd);  
  108.                gridStud.EditIndex = -1;  
  109.                gridStud.DataBind();  
  110.         }  
  111.     }  
  112.     protected void gridStud_RowEditing(object sender, GridViewEditEventArgs e)  
  113.     {  
  114.         gridStud.EditIndex = e.NewEditIndex;  
  115.         //gridStud.DataBind();  
  116.         binddata();  
  117.     }  
  118.     protected void gridStud_PageIndexChanging(object sender, GridViewPageEventArgs e)  
  119.     {  
  120.         gridStud.PageIndex = e.NewPageIndex;  
  121.         gridStud.DataBind();  
  122.     }  
  123.     protected void gridStud_RowDeleting(object sender, GridViewDeleteEventArgs e)  
  124.     {  
  125.         studentDAL stuDal = new studentDAL();  
  126.   
  127.             int studid = Convert.ToInt32(gridStud.DataKeys[e.RowIndex].Values["studentId"].ToString());  
  128.             stuDal.deleteStudent(studid);  
  129.           
  130.     }  
  131.   
  132.     protected void gridStud_RowDataBound(object sender, GridViewRowEventArgs e)  
  133.     {  
  134.   
  135.         if (e.Row.RowType == DataControlRowType.DataRow)  
  136.         {  
  137.             try  
  138.             {  
  139.                  
  140.                 HiddenField hidenGender = (e.Row.FindControl("HiddenGender"as HiddenField);  
  141.                 if (hidenGender.Value != "")  
  142.                 {  
  143.                  
  144.                     RadioButton rb1 = (RadioButton)e.Row.Cells[0].FindControl("RadioButton3");  
  145.                     RadioButton rb2 = (RadioButton)e.Row.Cells[0].FindControl("RadioButton4");  
  146.                     if (rb1 != null && rb2 != null)  
  147.                     {  
  148.                         if (hidenGender.Value == "Male")  
  149.                         {  
  150.                             rb1.Checked = true;  
  151.                         }  
  152.                         else  
  153.                         {  
  154.                             rb2.Checked = true;  
  155.                         }  
  156.                     }  
  157.   
  158.   
  159.                 }  
  160.   
  161.             }  
  162.             catch (Exception ex)  
  163.             {  
  164.   
  165.                 throw;  
  166.             }  
  167.   
  168.         }  
  169.     }  
  170. }  

Answers (6)