TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Dhimesh Parmar
NA
126
14.5k
i can'n perform edit and delete operation?
Feb 28 2018 3:09 AM
code like this
using
System;
using
System.Web.UI.HtmlControls;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
GridFun.BE;
using
GridFun.DAL;
using
GridFun.Common;
using
System.Data.SqlClient;
using
System.Data;
public
partial
class
Student : System.Web.UI.Page
{
studentDAL dal =
new
studentDAL();
studentBE bal=
new
studentBE();
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!IsPostBack)
{
//bal = new studentBE();
//dal = new studentDAL();
//gridStud.DataSource = dal.getdata();
//gridStud.DataBind();
binddata();
}
}
public
void
binddata()
{
gridStud.DataSource = dal.getdata();
gridStud.DataBind();
}
protected
void
BtnAdd_Click(
object
sender, EventArgs e)
{
dal =
new
studentDAL();
bal =
new
studentBE();
bal.name = txtStudentName.Text;
if
(RadioButton1.Checked)
{
bal.gender =
"Male"
;
}
else
{
bal.gender =
"Female"
;
}
bal.brithDate = Convert.ToDateTime(TextCalendar.Text);
bal.emailid = txtEmail.Text;
bal.mobilenumber = txtMobile.Text;
bal.status = 1;
bal.createdOn = DateTime.Now;
bal.modifiedOn = DateTime.Now;
dal.addStudent(bal);
Response.Redirect(
"Student.aspx"
);
}
protected
void
gridStud_RowUpdating(
object
sender, GridViewUpdateEventArgs e)
{
LinkButton btn = (LinkButton)gridStud.Rows[e.RowIndex].FindControl(
"linkUpdate"
);
if
(btn.CommandName ==
"UPDATE"
)
{
int
studentId = Convert.ToInt32(gridStud.DataKeys[e.RowIndex].Value.ToString());
TextBox txtStudName = (TextBox)gridStud.Rows[e.RowIndex].FindControl(
"txtStud"
);
RadioButton rd1 = (RadioButton)gridStud.Rows[e.RowIndex].FindControl(
"RadioButton3"
);
RadioButton rd2 = (RadioButton)gridStud.Rows[e.RowIndex].FindControl(
"RadioButton4"
);
TextBox txtBirthdate = (TextBox)gridStud.Rows[e.RowIndex].FindControl(
"txtDate"
);
TextBox txtEmail = (TextBox)gridStud.Rows[e.RowIndex].FindControl(
"txtEmail"
);
TextBox txtMobile = (TextBox)gridStud.Rows[e.RowIndex].FindControl(
"txtmob"
);
studentCommon c =
new
studentCommon();
SqlCommand cmd =
new
SqlCommand(
"studIUD"
);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(
"StatementType"
,
"UPDATE"
);
// cmd.Parameters.AddWithValue("studentId", studentId);
cmd.Parameters.AddWithValue(
"name"
, txtStudName);
if
(rd1.Checked)
{
cmd.Parameters.AddWithValue(
"gender"
,
"Male"
);
}
else
{
cmd.Parameters.AddWithValue(
"gender"
,
"Female"
);
}
cmd.Parameters.AddWithValue(
"brithDate"
, txtBirthdate);
cmd.Parameters.AddWithValue(
"emailid"
, txtEmail);
cmd.Parameters.AddWithValue(
"mobilenumber"
, txtMobile);
c.ExecuteNonQueryByCommand(cmd);
gridStud.EditIndex = -1;
gridStud.DataBind();
}
}
protected
void
gridStud_RowEditing(
object
sender, GridViewEditEventArgs e)
{
gridStud.EditIndex = e.NewEditIndex;
//gridStud.DataBind();
binddata();
}
protected
void
gridStud_PageIndexChanging(
object
sender, GridViewPageEventArgs e)
{
gridStud.PageIndex = e.NewPageIndex;
gridStud.DataBind();
}
protected
void
gridStud_RowDeleting(
object
sender, GridViewDeleteEventArgs e)
{
studentDAL stuDal =
new
studentDAL();
int
studid = Convert.ToInt32(gridStud.DataKeys[e.RowIndex].Values[
"studentId"
].ToString());
stuDal.deleteStudent(studid);
}
protected
void
gridStud_RowDataBound(
object
sender, GridViewRowEventArgs e)
{
if
(e.Row.RowType == DataControlRowType.DataRow)
{
try
{
HiddenField hidenGender = (e.Row.FindControl(
"HiddenGender"
)
as
HiddenField);
if
(hidenGender.Value !=
""
)
{
RadioButton rb1 = (RadioButton)e.Row.Cells[0].FindControl(
"RadioButton3"
);
RadioButton rb2 = (RadioButton)e.Row.Cells[0].FindControl(
"RadioButton4"
);
if
(rb1 !=
null
&& rb2 !=
null
)
{
if
(hidenGender.Value ==
"Male"
)
{
rb1.Checked =
true
;
}
else
{
rb2.Checked =
true
;
}
}
}
}
catch
(Exception ex)
{
throw
;
}
}
}
}
Reply
Answers (
6
)
Remove duplicates
Dynamic button control Second Click is Not Working but third