コード例 #1
0
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            //try
            //{
            // Get the index of the row being changed
            int    row_index = Convert.ToInt32((string)e.CommandArgument);
            int    id        = (int)GridView1.DataKeys[row_index].Value;
            string userid    = Session["UserId"].ToString();

            //if (e.CommandName == "Edit")
            //{
            //    Response.Redirect("~/Pages/Administrators/Index.aspx?page=audio/admin_background_audio_edit.ascx&id=" + id);
            //}

            if (e.CommandName == "UpdateSortKey")
            {
                TextBox txtSortKey = (TextBox)GridView1.Rows[row_index].FindControl("txtSortKey");
                if (txtSortKey != null)
                {
                    int sortkey = Convert.ToInt32(txtSortKey.Text);
                    media_obj.UpdateSortKey(userid, id, sortkey);
                    Response.Redirect("~/Pages/Administrators/Index.aspx?page=audio/admin_background_audio.ascx");
                }
            }

            if (e.CommandName == "UpdateStatus")
            {
                Control control = GridView1.Rows[row_index].Cells[3].Controls[0];
                if (((ButtonField)GridView1.Columns[3]).ButtonType == ButtonType.Image)
                {
                    ImageButton btnUpdateStatus = control as ImageButton;
                    Label       lblStatus       = (Label)GridView1.Rows[row_index].FindControl("lblStatus");
                    string      new_status      = string.Empty;

                    if (lblStatus != null)
                    {
                        string status = lblStatus.Text;
                        int    result = -1;
                        if (status == "Active")
                        {
                            new_status = "0";

                            result = media_obj.UpdateStatus(userid, id, new_status);
                            btnUpdateStatus.ImageUrl = "~/images/icons/unlock.gif";
                        }
                        if (status == "InActive")
                        {
                            new_status = "1";
                            media_obj.UpdateStatus(userid, id, new_status);
                            btnUpdateStatus.ImageUrl = "~/images/icons/lock.gif";
                        }


                        switch (result)
                        {
                        case -1:
                            Response.Write("<script>alert('Thông tin không đầy đủ.');window.location.href='Index.aspx?type=1&page=audio/admin_background_audio.ascx';</script>");
                            Response.End();
                            break;

                        case -2:
                            Response.Write("<script>alert('Cập nhật không thành công');window.location.href='Index.aspx?type=1&page=audio/admin_background_audio.ascx';</script>");
                            Response.End();
                            break;

                        case -3:
                            Response.Write("<script>alert('Không tồn tại id này');window.location.href='Index.aspx?type=1&page=audio/admin_background_audio.ascx';</script>");
                            Response.End();
                            break;

                        case 1:
                            Response.Write("<script>alert('Cập nhật thành công');window.location.href='Index.aspx?type=1&page=audio/admin_background_audio.ascx';</script>");
                            Response.End();
                            break;

                        default:
                            Response.Write("<script>alert('Lỗi hệ thống');window.location.href='Index.aspx?type=1&page=audio/admin_background_audio.ascx';</script>");
                            Response.End();
                            break;
                        }
                    }
                }
            }
        }