irrazor
شنبه 11 بهمن 1393, 12:44 عصر
سلام دوستان
من داخل گرید ویو از 3 تا دکمه استفاده میکنم(حذف.انتخاب.ویرایش)لاز م به ذکره هیچ کدوم پیشفرضخود asp نیست و خودم برنامه نوشتم(Templete) بجز حذف.
حال میخوام وقتی کاربر رو حذف کلیک میکنه ی پیغام بیاد("ایا از حذف اطلاعات مطمعآید") بعد شامل 2 تا دکمه لغو و بله باشه.گشتم این کد رو پیدا کردم ولی واس حذف کار نمیکنه(cancele میزنم باز حذف میکنه) ولی واسه سایر دکمه ها مثل ویرایش دقیق کار میکنه!
اینم کد:
this.GridView1.Attributes.Add("onclick", "javascript: return confirm('آیا از حذف اطلاعات مطمئن هستید ؟');");
این کد در گریدویو حذف:
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) {
string Cod1 = GridView1.Rows[e.RowIndex].Cells[3].Text.ToString();
delete1(Cod1);
}
void delete1(string Cod1)
{
Label1.Text = "";
Label2.Text = "";
try
{
SqlCommand sm1 = new SqlCommand("delete [LessonPC] where [کد درس]='" + Cod1 + "'", akoconnection);
akoconnection.Open();
sm1.ExecuteNonQuery();
Label1.Visible = true;
akoconnection.Close();
Label1.Text = "شما با موفقیت اطلاعات رو در جدول دروس کامپیوتر حذف کردید";
}
catch
{
Label2.Text = "حذف اطلاعات با مشکل مواجه شد";
}
inf();
}
اینم کد ویرایش در گریدویو:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) {
if (e.CommandName == "edt1")
{
GridViewRow row1;
int RowIndex;
row1 = (GridViewRow)(((Button)e.CommandSource).NamingCont ainer);
RowIndex = row1.RowIndex;
string Cod1 = GridView1.Rows[RowIndex].Cells[3].Text.ToString();
inf(Cod1);
}
}
void inf(string Cod1)
{
SqlDataAdapter da4 = new SqlDataAdapter("select * from [LessonPC] where [کد درس]='" + Cod1 + "'", akoconnection);
DataTable dt24 = new DataTable();
da4.Fill(dt24);
txtcod.Text = dt24.Rows[0][0].ToString();
txtname.Text = dt24.Rows[0][1].ToString();
txtunit.Text = dt24.Rows[0][2].ToString();
txtsemester.Text = dt24.Rows[0][3].ToString();
txtfield.Text = dt24.Rows[0][4].ToString();
txtday.Text = dt24.Rows[0][5].ToString();
txttime.Text = dt24.Rows[0][6].ToString();
txtm.Text = dt24.Rows[0][8].ToString();
txtm1.Text = dt24.Rows[0][9].ToString();
}
ی چیز دیگه که من میخوام فقط وقتی رو حذف کلیک میشه این پیغام بیاد اما با این کد که پیدا کردم نمیشه محدود کرد فقط میشه واس عملگر(دکمه یا گریدویو...) تعریف کرد.
من داخل گرید ویو از 3 تا دکمه استفاده میکنم(حذف.انتخاب.ویرایش)لاز م به ذکره هیچ کدوم پیشفرضخود asp نیست و خودم برنامه نوشتم(Templete) بجز حذف.
حال میخوام وقتی کاربر رو حذف کلیک میکنه ی پیغام بیاد("ایا از حذف اطلاعات مطمعآید") بعد شامل 2 تا دکمه لغو و بله باشه.گشتم این کد رو پیدا کردم ولی واس حذف کار نمیکنه(cancele میزنم باز حذف میکنه) ولی واسه سایر دکمه ها مثل ویرایش دقیق کار میکنه!
اینم کد:
this.GridView1.Attributes.Add("onclick", "javascript: return confirm('آیا از حذف اطلاعات مطمئن هستید ؟');");
این کد در گریدویو حذف:
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) {
string Cod1 = GridView1.Rows[e.RowIndex].Cells[3].Text.ToString();
delete1(Cod1);
}
void delete1(string Cod1)
{
Label1.Text = "";
Label2.Text = "";
try
{
SqlCommand sm1 = new SqlCommand("delete [LessonPC] where [کد درس]='" + Cod1 + "'", akoconnection);
akoconnection.Open();
sm1.ExecuteNonQuery();
Label1.Visible = true;
akoconnection.Close();
Label1.Text = "شما با موفقیت اطلاعات رو در جدول دروس کامپیوتر حذف کردید";
}
catch
{
Label2.Text = "حذف اطلاعات با مشکل مواجه شد";
}
inf();
}
اینم کد ویرایش در گریدویو:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) {
if (e.CommandName == "edt1")
{
GridViewRow row1;
int RowIndex;
row1 = (GridViewRow)(((Button)e.CommandSource).NamingCont ainer);
RowIndex = row1.RowIndex;
string Cod1 = GridView1.Rows[RowIndex].Cells[3].Text.ToString();
inf(Cod1);
}
}
void inf(string Cod1)
{
SqlDataAdapter da4 = new SqlDataAdapter("select * from [LessonPC] where [کد درس]='" + Cod1 + "'", akoconnection);
DataTable dt24 = new DataTable();
da4.Fill(dt24);
txtcod.Text = dt24.Rows[0][0].ToString();
txtname.Text = dt24.Rows[0][1].ToString();
txtunit.Text = dt24.Rows[0][2].ToString();
txtsemester.Text = dt24.Rows[0][3].ToString();
txtfield.Text = dt24.Rows[0][4].ToString();
txtday.Text = dt24.Rows[0][5].ToString();
txttime.Text = dt24.Rows[0][6].ToString();
txtm.Text = dt24.Rows[0][8].ToString();
txtm1.Text = dt24.Rows[0][9].ToString();
}
ی چیز دیگه که من میخوام فقط وقتی رو حذف کلیک میشه این پیغام بیاد اما با این کد که پیدا کردم نمیشه محدود کرد فقط میشه واس عملگر(دکمه یا گریدویو...) تعریف کرد.